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 is the total surface area of the figure shown?
How did European countries interact with their African colonies after World War I
sales taxis $0.065 per dollar where ray lives. what precent of a dollar is the sales tax​
f (x) = 3 x -1 and g(x) = x+ 2,find (f+ g) (x)
How did the Dao De Jing affect Chinese thought? A. It was a collection of the sayings of Confucius, which influenced the social structure of China. B. It was th
How is food security linked to food resource wars?
1. For the carnival, the park rented a dunking booth shaped as a rectangular prism. The booth is 3 1/2 ft wide, 3 1/2 ft long, and 8 ft tall. (a) What is the to
100 POINTS match each event from Romeo and Juliet to the correct stage of the dramatic structure -Romeo and Juliet get married -Juliet finds out that Romeo kil
What is that answer to this question?
A company owns rental properties and must pay for repairs and upkeep. If the monthly maintenance costs have an average of $3500.00 and a standard deviation of