I've just started trying to learn C++ and going through some tutorials I tried to write a few lines to assign a value to the variable x. It builds with no errors but when I run it it comes up with x and not 5. Some help (without laughing at me too much) would be greatly appreciated.
1 2 3 4 5 6 7 8 9 10 11 12
#include <iostream>
usingnamespace std;
int main()
{
int x;
x = 5;
cout << "x" << endl;
return 0;
}
Welcome CodeWizKid, your problem is, that when you do cout << "x" << endl;, it out puts
x
. Not the value of your int which is x. To fix this you will have to remove the quotation marks, so we output x and not a string literals: cout << x << endl;, output will be