mahlobogoanegontse mahlobogoanegontse
  • 02-05-2022
  • Computers and Technology
contestada

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

Respuesta :

mohammedtom32 mohammedtom32
  • 02-05-2022

#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;

}

Answer Link

Otras preguntas

If x/9=1 ,how do you know what x is? Explain
a salt truck drops 39 kilograms of salt per minute. how many grams of salt does the truck drop per second
What is the given name to a point of land extending into a body of water?
Jews were severely persecuted following the fall of this nation to the German army.
How many integers are in between -107,369 and 792,610?
Which are accurate descriptions of the English colonies in North America? Choose all answers that are correct. A. Unlike farmers in other colonies, Virginia pl
How do the symptoms of depression compare to those of attempted suicide?
A city planner has announced plans to establish a coastal city that will be the main trading port for a region. Knowing how the geographic location of New Orlea
In The Communist Manifesto, Karl Marx hypothesized that capitalism would fail if workers.?
Dylan sent junk email multiple times to his friend, wasting his friend's time. What did Dylan do wrong?