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

solve each proportion t/9=35/6
Is cellulose living material?
It is easy to move genes from one species to another. Is it right to do this? explain your position
Which sentence uses all of its object pronouns correctly? A. The deli worker gave she and he a free slice of ham. B. Eric told them and we about his journey. C.
Multiple Choice - Why do some flies live only 12 hours and others live 30 hours without food? a. because some flies ate more food before the food was removed
Why was U.S. support for the government in El Salvador controversial?
In such a spirit on my part and on yours we face our common difficulties. uses analogy. uses metaphor. establishes the speaker's authority. appeals to logic. tr
what is 1430÷75 in fraction form
the goal of the historian is to create accounts of events
What are three equivalent ratios for 5:45?