Explore Westonci.ca, the top Q&A platform where your questions are answered by professionals and enthusiasts alike. Connect with a community of professionals ready to help you find accurate solutions to your questions quickly and efficiently. Our platform provides a seamless experience for finding reliable answers from a network of experienced professionals.

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;

}