Discover a world of knowledge at Westonci.ca, where experts and enthusiasts come together to answer your questions. Get detailed answers to your questions from a community of experts dedicated to providing accurate information. Join our platform to connect with experts ready to provide precise answers to your questions in different areas.

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;

}

Thank you for visiting. Our goal is to provide the most accurate answers for all your informational needs. Come back soon. Thanks for using our platform. We aim to provide accurate and up-to-date answers to all your queries. Come back soon. Discover more at Westonci.ca. Return for the latest expert answers and updates on various topics.