• Create Account

# My first Program

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

5 replies to this topic

### #1C++Bernie++C  Members   -  Reputation: 100

Like
0Likes
Like

Posted 21 January 2011 - 04:28 AM

This is my first program i have made, i made this program to practice what i have learned the past weeks,

let me now how it is and if you need to see code tell me for improvements.

#include <iostream>
#include <cstdio>
#include <cstdlib>

using namespace std;

int main()

{
cout << "ON THIS PROGRAM YOU WILL HAVE THE CHOICES ON WHAT TO DO " << endl << endl << endl;

cout << "Your walking on a rainy dark night, suddenly a lightning flashes and you" << endl;
cout << "see a castle roof inside the forest." << endl << endl;

cout <<  "Press 1 to go inside the forest. " << endl;
cout <<  "Press 2 to keep walking home. " << endl;

int choice;
cin >> choice;

switch(choice)
{
case 1:
cout << " you have enter the dark woods of chaos, you now find yourself, " << endl;
cout << " lost inside the forest, you then start walking to the castles door" << endl;
cout << " you find a group of people gathering infront of the castle door, " << endl;
cout << " there yelling that there going to find the source that is keeping " << endl;
cout << " them trap in the dark forest." << endl << endl;

cout <<  "Press 3 to enter the castle for shelter. " << endl;
cout <<  "Press 4 to Grab weapons and join the fight. " << endl;

break;
case 2:
cout << " You got home and went to bed thinking what would of " << endl;
cout << " happened if you went to the castle. " << endl;

cout << " <--------------GAME OVER--------------> " << endl;

cin.get();
cin.ignore();
return 0;
}

cin >> choice;

switch(choice)
{
case 3:

cout << " The door is locked, solve the math problem to enter the castle" << endl;
cout <<   " 5(x - 3) = 35   " << "enter right answear for x to open door." << endl;

break;

case 4:

cout << "you grab a weapon and join the people that were going to war" << endl;
cout << "you walk north into the forest and you find two paths, " << endl;
cout << "but one is blocked with a big giant stone, you go to the path " << endl;
cout << "that is not blocked, sadly there was a giant hole on the way" << endl;
cout << "you go back to the castle " << endl;

cout << " The door is locked, solve the math problem to enter the castle" << endl;
cout <<   " 5(x - 3) = 35   " << "enter right answear for x to open door." << endl;

break;
}

int x;
cin >> x;

if ( x == 10 )
{

cout << "answear is correct, proceed" << endl << endl;
}

else if ( x != 10 )
{

cout << " Bad answear, the door shots a curse into you " << endl;
cout << "    <----------GAME OVER--------------->" << endl;
cin.get();
cin.ignore();
system ("PAUSE");
return 0;
}

cout << " you search the castle, and notice that it's empty, but you see a " << endl;
cout << " nice chest that you aproach." << endl << endl;

cout << "!!!!chest talks to you and asks you a question!!!!!" << endl << endl;
cout << "??????_How many types of flow controll are there_??????" << endl << endl;

int answear;
cin >> answear;

if ( answear == 3 )
{
cout << " chest opens and you find a TNT inside it. " << endl << endl;
cout << " You grab the TNT and go back outside. " << endl << endl;
}

else if ( answear != 3 )
{
cout << " Wrong answear, the door closes you are trap inside forever " << endl;
cout << "            <---------------GAME OVER------------->         " << endl;

cin.get();
cin.ignore();
system ("PAUSE");
return 0;
}

cout << "you find no other choice but to grab a weapon and join the fight" << endl << endl;
cout << "you walk north into the forest and you find two paths, " << endl;
cout << "but one is blocked with a big stone, luckily you" << endl;
cout << " have a TNT and you can choice were to go. " << endl << endl;

cout << " 5: Plant TNT destroy stone to go that way. " << endl;
cout << " 6: Follow the path that is open. " << endl << endl;

cin >> choice;

switch (choice)
{

case 5:
cout << " Solve problem to activate TNT for 10 seconds " << endl;
cout << " 5(4x - 3) + 8 = -2 " << endl << endl;
break;

case 6:
cout << "you go to the path that is not blocked, sadly there was a giant hole on the way" << endl;
cout << "you go back to place the TNT on the stone. " << endl << endl;

cout << " Solve problem to activate TNT for 10 seconds " << endl;
cout << " 5(4x - 3) + 8 = -2 " << endl << endl;
break;
}

double a;
cin >> a;

if ( a == 0.25 )
{

cout << "           TNT ACTIVATED----------<   " << endl;
cout << "10, 9, 8, 7, 6, 5, 4, 3, 2, 1 BOOM!" << endl;
}

else if ( a != 0.25 )
{
cout << " TNT explodes immediately " << endl;
cout << "<--------GAME OVER-------->" << endl;

cin.get();
cin.ignore();
system ("PAUSE");
return 0;
}

cout << "Path is open, when you enter you find out that it's a " << endl;
cout << "demons lair, you are now fighting with a demon. " << endl << endl;

cout << "Solve the problems to attack demon" << endl<< endl;

cout << " 243 * 28 = n " << endl;

cin >> x;

if ( x == 6804 )
{

int d;
d = 150 - 50;

cout << "Your life: " << 50 << endl << "Demons life: " << 150 << endl << endl;
cout << "You attack the demon" << endl << endl;
cout << "Your life: " << 50 << endl << "Demons life: " << d << endl;
}

else if ( x != 6804 )
{
cout << "Demon kills you " << endl;
cout << "<--------GAME OVER-------->" << endl;

cin.get();
cin.ignore();
return 0;
}

cout << " 5 * 4(23) / 3 = x" << endl;

cin >> x;

if ( x == 705 )
{

int d;
d = 100 - 50;

cout << "Your life: " << 50 << endl << "Demons life: " << 100 << endl<< endl;
cout << "You attack the demon" << endl << endl;
cout << "Your life: " << 50 << endl << "Demons life: " << d << endl << endl;
}

else if ( x != 705 )
{
cout << "Demon kills you " << endl;
cout << "<--------GAME OVER-------->" << endl;

cin.get();
cin.ignore();
return 0;
}

cout << " whats the average of 23 + 52 +12: " << endl;

cin >> x;

if ( x == 29 )
{
int d;
d = 50 - 50;

cout << "Your life: " << 50 << endl << "Demons life: " << 50 << endl<< endl;
cout << "You attack the demon" << endl << endl;
cout << "Your life: " << 50 << endl << "Demons life: " << d << endl << endl;
}

else if ( x != 29 )
{

cout << "Demon kills you " << endl;
cout << "<--------GAME OVER-------->" << endl;

cin.get();
cin.ignore();
return 0;
}

cout << "You have killed the demon that was cursing the forest now your able to" << endl;
cout << "exit the dark forest " << endl;

cout << "You went back home happy to be alive <img src='http://public.gamedev.net/public/style_emoticons/<#EMO_DIR#>/biggrin.gif' class='bbc_emoticon' alt=':D' />" << endl << endl;

cout << "           CEDITS              " << endl;
cout << "    Programer: Bernie Ochoa    " << endl;
cout << "    Story: Bernie Ochoa        " << endl;
cout << "    Company: Core-Bros         " << endl;
cout << "    http://corebros.webs.com/  " << endl;
cout << "<------THANKS FOR PLAYING----->  " << endl;

cin.get();
cin.ignore();
return 0;
}



also how do i post my work in my profile? this question was answeared thanks .

### #2The Communist Duck  Members   -  Reputation: 154

Like
1Likes
Like

Posted 21 January 2011 - 10:27 AM

Currently you have not posted anything. Edit your post and click the < > button to give you code tags and paste between those. That, or the code formatting is being sorted right now.
Either that, or you're expecting us to rate the code without actually giving us code.
And to post work into your profile you need to become a GD.NET+ member. It costs money for the subscription, but you get a dev journal and space on here for projects and support the site. If you've only just written your first project, it may be a little much (unless you want to support the site).

### #3Josh Petrie  Moderators   -  Reputation: 7833

Like
0Likes
Like

Posted 21 January 2011 - 11:29 AM

Please don't use polls in this forum.

And to post work into your profile you need to become a GD.NET+ member. It costs money for the subscription, but you get a dev journal and space on here for projects and support the site. If you've only just written your first project, it may be a little much (unless you want to support the site).

You don't need a GDNet+ membership for journals, they are freely available to all users now. You also don't get storage space any longer, period. So the OP can just create a journal and post his projects in there if he/she likes.

### #4C++Bernie++C  Members   -  Reputation: 100

Like
0Likes
Like

Posted 21 January 2011 - 12:35 PM

Currently you have not posted anything. Edit your post and click the < > button to give you code tags and paste between those. That, or the code formatting is being sorted right now.
Either that, or you're expecting us to rate the code without actually giving us code.
And to post work into your profile you need to become a GD.NET+ member. It costs money for the subscription, but you get a dev journal and space on here for projects and support the site. If you've only just written your first project, it may be a little much (unless you want to support the site).

Alright thanks for your help i posted the code now, let me now how it is.

### #5boogyman19946  Members   -  Reputation: 1380

Like
1Likes
Like

Posted 21 January 2011 - 12:46 PM

I believe your math is incorrect. Where it says 5(x - 3) = 35, x does not equal 4. It equals 10:

5(x - 3) = 35
x - 3 = 7 (divide by 5)
x = 10 (add 3 to both sides)

A thing I can speak of is:
- You do not have to declare a separate variable for every new input you get. You can reuse the previously initialized variables.

For example: For every choice branch you create a new choice variable, but instead, you could keep the original one that you are no longer using. Same with the math equations. Once you check if the answer is correct and no longer need the variable, you can overwrite the value it stores with something else.

Other than that, I think it's pretty good.

- Java API Documentation - For all your Java info needs
- C++ Standard Library Reference - For some of your C++ needs ^.^

### #6C++Bernie++C  Members   -  Reputation: 100

Like
0Likes
Like

Posted 21 January 2011 - 04:15 PM

I believe your math is incorrect. Where it says 5(x - 3) = 35, x does not equal 4. It equals 10:

5(x - 3) = 35
x - 3 = 7 (divide by 5)
x = 10 (add 3 to both sides)

A thing I can speak of is:
- You do not have to declare a separate variable for every new input you get. You can reuse the previously initialized variables.

For example: For every choice branch you create a new choice variable, but instead, you could keep the original one that you are no longer using. Same with the math equations. Once you check if the answer is correct and no longer need the variable, you can overwrite the value it stores with something else.

Other than that, I think it's pretty good.

Nice bro i didn't know that, thanks for the info and the math check, i already adjust and fix the code so it will be at its best, let me know if the code is at its best now.

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

PARTNERS