random number generator (terminal)

Run Settings
LanguageC++
Language Version
Run Command
#include <iostream> #include <iomanip> using namespace std; int main () { int a; int y=0; int guesses=0; int games=0; double percentage; int RandomNumber; char response; int answer1; cout << fixed << setprecision(2); srand ( 99 ); cout << "Would you like to play? (enter y or n)" << endl; cin >> response; cin.ignore(); while ( response == 'y' ) { a = rand() %7 + 13; cout << "Enter your guess" << endl; cin >> answer1; cin.ignore(); while ( answer1 != a ) { if ( answer1 > a ) { cout << "Your guess is greater than the random number." << endl; cout << "Enter your guess" << endl; cin >> answer1; cin.ignore(); guesses +=1; } if ( answer1 < a ) { cout << "Your guess is less than the random number." << endl; cout << "Enter your guess" << endl; cin >> answer1; cin.ignore(); guesses +=1; } } if ( answer1 == a ) { cout << "Congratulations. You guessed correctly." << endl; games +=1; cout << "Would you like to play again? (enter y or n)" << endl; cin >> response; cin.ignore(); } } cout << "Number of Games played is " << games << endl; cout << "Number of guesses is " << games + guesses << endl; percentage = (double) games / (games + guesses); cout << "Your total winning percentage is " << percentage << endl; cout << "Thanks for playing. Come back again." << endl; return 0; }
Editor Settings
Theme
Key bindings
Full width
Lines