-
Noob Programmer
Well I needed some help with my C++ programming and decided to join this forum. I enjoy learning new things. This is my first post and you may all just call me "Muner".
I have a programming class which I am beginning to struggle. Now one of my assignments was find all the errors in a code and comment on what is wrong.
This is the code to clean up:
Code:
//Specification: Display a menu
//Find Errors in this program
#include <io>
main ( )
}
cout >> "Choose From Martha's Menu:/n"
cout << "1 - Dinner"
cout << endln << 2 - Lunch";
cout << endln << "3 - Breakfast";
cout << "Enter a number:"
int Choice = 0;
cin << choice
cout << "\n You Choose " << choice;
return 0;
}
Now this is what I was able to find:
Code:
//Specification: Display a menu
//Find Errors in this program
#include <iostream>
using namespace std;
int main ( )
{
cout << "Choose From Martha\'s Menu:/n";
cout << "1 - Dinner";
cout << endl << "2 - Lunch"; // doesn't "endl" have to be in the end?
cout << endl << "3 - Breakfast";
cout << "Enter a number: ";
int Choice = 0;
cin >> choice
cout << "You Choose /n" << choice;
return 0;
}
I did not add comments to the ones I was able to find, but if someone could explain so I can understand this a lot better would be appreciated.
-
>doesn't "endl" have to be in the end?
"What's the difference between std::endl vs. \n"
In other words, endl is functionally equivalent to a newline (which can be placed anywhere in a string). However, because endl also clears the output buffer, it makes sense to place it at the end of your output. It isn't really an error, but inefficient/unnecessary programming practice.
That said, you forgot a semicolon in your cin line, and I'm not sure why you moved the newline character in your final line of code.
-
Isnt there sopposed to be a "cin << variable_name" at the end of the program.
P.s. I may be wrong I am only starting out to.
-
"/n" is wrong... it should be "\n"
Oh and variables are case-sensitive meaning that if you capitalize the 'C' in "Choice" you need to keep it that way. "Choice" and "choice" are two totally different things. So you need to capitalize the 'C' in "choice" on that "cin >> choice" line.
-
Thank you all for the help. As for the std:: endl I forgot what buff means. ^ ^"
I mean so far I have understood everything said so far.