I'm faily sure this is easy to fix and would really appreciate some pointers! Thanks! :D
// Fait par Sam le Roux =D
#include <iostream>
#include <time.h>
#include <string>
using namespace std;
int main() {
cout << "Programme fait en C++ par Sam le roux :D\n";
int tries,guess,secret;
string play;
srand ( time(NULL) );
secret = rand() % 51;
tries = 0;
cout << "Guess the number!\n" << "It's between 1 and 50, you have 5 tries.\n";
do {
cout << "What's your guess?: ";
cin >> guess;
if(guess>secret) {
cout << "Your guess is too high!\n";
tries++;
}
else if(guess<secret) {
cout << "Your guess is too low!\n";
tries++;
}
else if(guess==secret) {
guess = 0;
cout << "You won! Congratulations!\n";
cout << "Play again? (Y/N): ";
cin >> play;
if(play == "Y");
main();
}
}while(tries<5);
if(tries>=5) {
cout << "You lost! The number was: " << secret << "\n";
cout << "Play again? (Y/N): ";
cin >> play;
if(play == "Y");
main();
}
return 0;
}


Sign In
Create Account

Back to top










