Okay, I'm new at C++ and I'm going through some tutorials.
I tend to copy my tutorials down and compile them to see if it works. And this is not compiling.
Your cout operators are pointing the wrong way.
Try these: <<
;)
To remember these I have always used the analogy of cout "pipes data out" and cin "pipes data in". My programming relative told me that and not once have I had that problem.
Once again, stupid mistake! This is hilarious.
Alright, thanks eker.
See, that's what happens when you stop coding for a few days when you're a noob like me.
Ok, I'm onto another exercice.
The coding works just fine, but as soon as I do enter the correct number, it closes without letting me see the last cout statement.
// Guess My Number
// The classic number guessing game
#include <cstdlib>
#include <iostream>
#include <ctime>
usingnamespace std;
int main()
{
srand(time(0)); // seed random number generator
int theNumber = rand()%100 + 1; //random number between 1 and 100
int tries = 0, guess;
cout << "\tWelcome to Guess my Number\n\n";
do
{
cout << "Enter a guess: ";
cin >> guess;
++tries;
if (guess > theNumber)
cout << "Too high!\n\n";
if (guess < theNumber)
cout << "Too low!\n\n";
} while (guess != theNumber);
cout << "\nThat's it! You got it in " << tries << " guesses!\n";
return 0;
char c;
cin >> c;
}
"Return statement:
The return statement stops execution and returns to the calling function. When a return statement is executed, the function is terminated immediately at that point, regardless of whether it's in the middle of a loop, etc. "