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

what is a prefix for dote?
you shoot a model rocket into the air with a speed of 18.2 m/s. now high does the rocket go?
What is social Darwinism and how was it tied to imperialism?
what are facts on Loyalists?
The width of a computer monitor is 30 cm. If the perimeter is 144 cm, what is the area of the computer monitor?
Solve the equation: 1/4 + w = 6 1/3
Show that n^2-1 is divisible by 8,if 'n' is an odd positive integer.
What do you think was the most serious problem faced by settlers in Virginia? Why?
what is the fraction ten twelfths in it's simplest form ?
Is There Still Slavery in the World? Please help me :)