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

Where do the cranial nerves originate? Where do the spinal nerves originate?
What is the coefficient of y in the expression 12+3y-2x?
(X+12) 2 ÷ x2-144 ×-12. 12×-144
Buck drove 220 miles in 5 hours. What was his average rate of speed?
what time is 9 hours and 30 minutes before. 4:25
Horace read 160 pages in 4 hours. How many pages can he read in 6 hours??
What is the lateral area of the rectangular prism? Assume the prism is resting on its base. A. 135 in2 B. 270 in2 C. 300 in2 D. 310 in2
The neolithic revolution is most closely associated with....
What is the change in number of individuals in a population over time? A. population decrease B. population stability C. population growth D. population resista
The dimensions of a brick that weighs 25 N are 0.19 m × 0.07 m × 0.095 m. What pressure does the brick exert on the ground if it is resting on its largest face?