Hey I need help I am supposed to create a simple guessing game using c++
This is the instructions:
Complete project 5, page 283, as modified below, using C++.
Use an outer loop to control the number of rounds to play
Generate a new random number at the beginning of each round
Use an inner loop to control multiple guesses per round
Give the user feedback for each guess: High, Low, Exact
Terminate the inner loop with a correct guess or the maximum number of guesses
Ask the user whether they want to play another round at the end of the outer loop
Turn in a single zip file containing either your Visual Studio project folder or your .cpp file. Name the zip file “First_Last_HW5”, where “First Last” is replaced with your First and Last names.
This is what I have so far but I am stuck:
#include "stdafx.h"
#include <iostream>
#include <ctime>
using namespace std;
int main()
{
int count= 0;
int answer;
int guess;
srand(time(0));
guess = rand() %101
do{
cout << "Enter a number between 1 and 10";
cin>> answer;
}
if (answer > guess)
{
cout <<"Your guess is too high" << endl;
} else if (answer < guess)
{
cout << "Your guess is too low" << endl;
} else{count++;
}while (answer!=guess)
if (answer == guess)
cout <<"You guessed it" <<endl;
system("pause");
return 0;
}
The compiler says my do statement error expected a ";"
The interesting thing about the compiler error is they not only tell you what the problem is, but also what line it's on. Although in this case, the error was on the line before the line it told you (which is common, if you don't see the error on the actual line, try checking a line or 2 above/below it)
guess = rand() %101
notice that you're missing a semicolon on that line, which is exactly what the compiler error was telling you.
;P
Learning to read and understand compiler errors is actually an important skill to get the hang of when programming.
your errors are because you have a semicolon after the statment when it isnt needed and also in the last else if count++ isnt a condition you can check. you need to do
else{
count++;
}
// Klaeton_Beyers_HW5.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
#include <ctime>
usingnamespace std;
int main()
{
int answer;
int guess;
srand(time(0));
guess = rand() %101;
cout << "Enter a number between 1 and 10 ";
cin>> guess;
if (guess > answer);
cout <<"Your guess is too high" << endl;
cout<< "Guess again" <<endl;
cin>> guess;
if (guess <answer);
cout <<"Your guess is too low" << endl;
cout <<"Guess again" << endl;
cin>> guess;
if (guess = answer)
cout<<"CONGRADULATIONS!!!! You have guessed my number"<<
system("pause");
return 0;
}
just wondering if I did anything wrong because I am confused about the random number and how to generate it.