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 are two fractions equivalent to 2/8?
Why are stories important?
why do you think both the US and Soviet Union wanted to promote their system for other countries?
The passage below is from a secret communication issued by the German Foreign Office in January 1917. We make Mexico a proposal or alliance on the following bas
Which is the closest synonym for the word relevant?
Spencer bought 3 books of stamps and mailed a package. It cost 4.50 to mail the package. Define a variable and write an expression to represent the total amount
4. Solve the equation, please type your steps and your work: 3x – 5 = -3
Mo reads 3 pages in 2 hours. What is the constant of proportionality?​
I need help quick I give brainliest
Is the graph increasing, decreasing, or constant? O A. Constant O B. Increasing C. Decreasing