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

Help I don't get this!
How might an economist gather empirical data to test the proposed relationship between money and the price level?
How do i prove this
Which part of earth's interior is liquid? a. inner core b. outer core c. mantle d. crust?
two sides of a triangle are 5cm and 7cm what is the third side
How many kilometers are equivalent to 3,570 meters?
how does the number of valence electrons for elements change across a period
For those who need help with Paleozoic Era: Life Explodes.... here are the answers. :-) 1. B) Gondwana 2. B) They fused into Pangaea 3. B) seas
You are given two fatlike solid substances and determine that sample a has a higher melting point than sample b. sample a, therefore,
In a survey 5/10 of the students chose a dog and 1/10 chose a fish as their favorite pet. What fraction shows the students who chose a dog or a fish as their fa