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 name of the biome in which you can encounter an elephant (in natural environment of course)
In the late 20th century , the green revolution had the greatest impact on
In the late 20th century , the green revolution had the greatest impact on
You are trying to save $20 a week to buy and use cd player. During the last 4 weeks you have saved $35, $15, $10 and $12. How much do you need to save this week
accurate estimation of 75-33
Can some one help me with this Please help
A stadium can hold 20,000 people when it is full. The table below shows the number of people that attended concerts at the stadium over a 3-day period. Day Nu
For the given value of a , find - a and |a| 1. a = 10.2 2. a = - 14 a = 1 over 2 Anyone!? ;o help me !?
You have 10 apples in a basket. 10 children come to you and each one of them ask for an apple. You want to give all the apples to each one of them, but still ke
the difference of 17 and 5 times a number.