384,828 views
30 votes
30 votes
How to write a C++ program that lets the user guess if a randomly generated integer is even or odd then the computer lets them know if they are correct or incorrect

User Uux
by
3.0k points

1 Answer

14 votes
14 votes

#include <iostream>

using namespace std;

int main() {

string input;

string rand_type;

int number=rand()%100+1; //number between 1 and 100

if ( number % 2 == 0)

rand_type= "even";

else

rand_type="odd";

cout << "your guess: ";

cin >> input;

if ( input== rand_type)

cout << "correct.\\";

else

cout << "incorrect.\\";

return 0;

}

User Anders Fjeldstad
by
3.8k points