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

Which element has 16 neutrons, 15 protons, and 15 electrons?
Which expression is equivalent to 83 x 52? A 5(80 x 3) B. 5x (80+3) C. 80 (3x5) D. 80 x (3+5)
Question 4 (1 point) Cultural divergence is when is when one group starts purposely living in isolation from others. True False
Josh owed Gregg $2.00. He offered to buy Gregg a small cup yogurt for $1.25 with 3 toppings at 15¢ each. How much does Josh now owe Gregg?
Which of the following is a result of limiting weed growth through mulching? A. lowers the need for herbicides B. increases the amount of pests C. lowers the am
0.6×8 and tell me how you got the answer pls[tex]0.6 \times 8[/tex]​
HELP ME PLS ASAP NO LINKS!
George is 22 years old, single, and has just started his first job. He saves 5 percent of his monthly income for retirement. Kirsten is 30 years old and married
12. According to Belbin, the extravert role that describes an energetic, high-strung person with drive to get things done is called a(n):
simply log 64 - log 128 + log 32​