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

Before the Agricultural Revolution, many people lived in rural areas because
A number is not an integer what type of number can it be
Why do the countries belonging to OPEC not want to produce too much oil at one time?
what is the context clue in he grabbed his lunch from kitchen table in went to school
Which of these statements is false? A. Damaged relationships can be repaired. B. The first sign of a problem with a relationship is a feeling of anger. C. Othe
what is the greatest common factor of 49 and 63
when solving a real-world problem to find a persons age , would a negative solution make sense ?
What is 1.65 divided by 100?
centerville has a population of 9000. north fork has 18/25 population of centerville. what is the population of north fork?
What is a example of a variable