207k views
25 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

1 Answer

10 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 Sthzg
by
4.9k points