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

Though people in the Khmer Empire practiced Buddhism and Hinduism, their great temple complexes were only constructed to honor Buddhism. True or false
What is the answer ?
Given: <SPT = <RQT, ST = RT Prove: PR = QS​
Please help~~~ thank you ❤️
(18x² – 3x²+x-1) ÷ (x² – 4)​
In Journey to the Center of the Earth Chapters 19-21 Why was Harry upset at the end of the chapter? A. He thought his uncle was leaving him B. He thought Hans w
Plz help me with this question
The football team scored 28 points in the first game. 35 points in their second game, and 17 points in the third game About how many points were scored in all t
what is the magnitude of an electric field which will balance the weight of an electron on the surface of earth ?​
Find the inequality represented by the graph