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

2/5 ab What are the factors of the expression? Drag all of the factors of the expression into the box. please help me :D the points are 50
PLEASE HELP!!!! How are Darwin’s Finches an example of evolution?
Why is psychology considered a science??
Which of the following outcomes is the best example of how health is a factor that affects population? A. More access to medicine and doctors can help people li
Find the value of the ratio for 63:135
Don't get it ? I need help from someone
How to analyse the mood of the us public?
Suppose you had a mixture of iron pellets, pebbles, and small wood spheres, all of which were about the same size. how would you seperate the mixture
What are slight attractions that develop between oppositely charged regions of nearby molecules are called?
How many solutions can be found for the linear equation? 6( 3x/2 + 4) - 10 = 1/2 (4x + 16) A) no solutions B) one solution C) two solutions D) infinitely