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 phylum has animals with a central cavity and mouth;and most of them have tentacles?
the temperature on mars ranges widely from -207 f to 80 f find the average of the temperature extremes on mars
How do I write 4.76325 as a fraction?
Solve the following equation 3m^2=3-8m. Find both values
what are some physical changes that occur at school? at home ? in nature ?
what type of bond is methane?
two forms of solid carbon diamond and graphite different in their physical properties due to the differences in their
Name the two lines and the transversal that form each pair of angles
Prove the identity: cos(3x) + cos(x) = 2cos(2x)cos(x) I'm almost done with my homework, just got stuck on this one.
A bank charges $3 each time you use an out of network ATM. at the beginning of the month, you have $1500 in your bank account. you withdrawal $60 from your bank