Westonci.ca is the premier destination for reliable answers to your questions, provided by a community of experts. Experience the convenience of finding accurate answers to your questions from knowledgeable professionals on our platform. Connect with a community of professionals ready to help you find accurate solutions to your questions quickly and efficiently.

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

Sagot :

#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.\n";

else

   cout << "incorrect.\n";

 return 0;

}