Jump to content
  • Advertisement
Sign in to follow this  
XandX2005

My first program...

This topic is 3516 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

So this is my first custom console program I wrote, Its called EatNDump. Tell me what you think, let me know if there is any ways things could've been done differently and efficiently. BTW, how do I put this in a post embedded scroll window? #include <iostream> using namespace std; int main() { char main, side1, side2, desert; double dump, food; food = 0.0; dump = 0.0; cout << "What would you like for your main course? " << endl; cout << "1. Steak" << endl; cout << "2. Chicken" << endl; cout << "3. Pork" << endl; cout << "4. Turkey" << endl; cout << "\n\n"; cin >> main; switch(main) { case '1': cout << "Good choice!\n" << endl; food += 0.8; break; case '2': cout << "Very good choice!\n" << endl; food += 0.5; break; case '3': cout << "Pigs taste good too!\n" << endl; food += 0.6; break; case '4': cout << "The triptofan may make you sleepy!\n" << endl; food += 0.7; break; default: cout << "Selection not found!\n"; } cout << "What would you like your first side dish to be? " << endl; cout << "1. Peas and Carrots" << endl; cout << "2. Broccoli" << endl; cout << "3. Side Salad" << endl; cout << "\n\n"; cin >> side1; switch(side1) { case '1': cout << "Tasty and Healthy!\n" << endl; food += 0.3; break; case '2': cout << "Healthy and Light!\n" << endl; food += 0.2; break; case '3': food += 0.3; char salad; cout << "\n"; cout << "What type of dressing would you like?" << endl; cout << "1. Thousand Islands" << endl; cout << "2. Homestyle Ranch" << endl; cout << "3. Chunky Bleu Cheese" << endl; cout << "\n\n"; cin >> salad; switch(salad) { case '1': cout << "Our chef specialty!\n" << endl; food += 0.1; break; case '2': cout << "Better than youve ever had!\n" << endl; food += 0.2; break; case '3': cout << "Ohhhh so good!\n" << endl; food += 0.4; break; default: cout << "Selection not found"; } cout << "\n\n"; break; } cout << "And for your second side? " << endl; cout << "1. Steak Fries" << endl; cout << "2. Baked Potato" << endl; cout << "3. Garlic Mashed Potatos" << endl; cout << "\n\n"; cin >> side2; switch(side2 ) { case '1': cout << "Don't forget that you can have as many as you want!\n" << endl; food += 0.6; break; case '2': cout << "My personal Favorite!\n" << endl; food += 0.3; break; case '3': cout << "These are very popular around here!\n" << endl; food += 0.5; break; } if(food<=1.7) { cout << "What would you like for desert? \n"; cout << "1. Apple pie\n"; cout << "2. Peach Cobbler\n"; cout << "3. Banana Split\n"; cout << "\n\n"; cin >> desert; switch(desert) { case'1': cout << "Homemade is the greatest!\n"; food += 0.9; break; case'2': cout << "Very Very Tasty!\n"; food += 1.2; break; case'3': cout << "Gotta love them nanners!\n"; food += 0.6; break; } } if(food>=1.8 && food<=2.2) cout << "You ate just enough.\n If you ate any more you would've popped!"; if(food>=2.3) cout << "You ate too much, puked everywhere and humiliated yourself!"; dump = food*0.3; cout << "\n\n"; cout << "You ate " << food << " lbs of Food!\n"; cout << "Your poop afterwards weighed " << dump << " lbs\n" << endl; return 0; }

Share this post


Link to post
Share on other sites
Advertisement
three things that you might consider doing

1. Use encapsulation. It may not be important with this particular code, but it will be easier to read with other programs and it is best to build habits early

2. Loops. Allow the user to run through your program again or make as many choices as they want from any menu, keep track of it all, AND display at the end. This would be a much easier goal with the first suggestion as well.

3. build with an object of food each food as a type, weight, and name...


And IIRC you could initialize the variables you set to 0 when you declared them...

Share this post


Link to post
Share on other sites
Quote:
Original post by Durakken
three things that you might consider doing

1. Use encapsulation. It may not be important with this particular code, but it will be easier to read with other programs and it is best to build habits early


What is encapsulation?

Quote:


3. build with an object of food each food as a type, weight, and name...

And IIRC you could initialize the variables you set to 0 when you declared them...


Build with an object of food?

which variables are you talking about?

And do I have to list them seperatley to declare them all as 0?

Share this post


Link to post
Share on other sites
ecapsulation is if i got the lingo right when you do this

main() {

menu1();
menu2();
}

menu1() {

...

}

menu2() {

...

}

etc

for like steak, it is a main course meal, it's name is steak, and has a weight or whatever of 0.8

so you can make a class for food

food.type = main course
food.name = steak
food.weight = 0.8

I'm pretty sure it could be written this way but i haven't thought it all out. regardless it's probably better to get use to this type of thing for larger programs


and no i don't believe you have to list them separately, but i am not certain. In certain cases it is considered bad form while others it is considered good. i completely forget why either is considered this way but i'm pretty sure it has something to do with readability.

Share this post


Link to post
Share on other sites
Is that C++?

Where should I learn that, and I'd prefer a web site, because I cant get every book from a library?

And what do I write it in?

If it isnt C++ i would like 2 know what it is plz.

Share this post


Link to post
Share on other sites
Quote:
Original post by Orechalcos

Where should I learn that, and I'd prefer a web site, because I cant get every book from a library?

And what do I write it in?


Yes this is C++

You can learn C++ all over the web, I have been learning from Microsoft

You need to download and install MS Visual C++ Express

As you are learning, I find it easier to absorb the info by creating your own programs, like the one I posted above.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!