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

The ratio of the dide lengths of a triangle is 2 : 4 and the perimeter is 55 cm what is the length of the shortest side
You're caring for three children in your home: a three-year-old, a four-year-old, and a two-month-old infant. The infant often become hungry and wants to be fed
Christine is 9 years older than don. six years ago don was 1/2 as old as christine. how old are they now
Prove that acceleration is perpendicular to velocity
Parallel structure is important in writing because it
Which of the following particles has almost no mass?
What should you do if the choking victim is a pregnant woman? Give abdominal thrusts Do nothing; you don't want to hurt the baby Ask permission and give chest
Manu's suffers from a rare genetic disorder that does not allow incoming light from her eyes to be transmitted to her brain. because of manu's disorder, which p
In the accompanying diagram angle 1 and angle 2 are supplementary what is m angle 3
how do companies benefit by offering sustainable products and services?