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

Find the first fourth and eighth terms of A(n)=-2•5^n-1
How do I find my spirit animal? I was reading this paper talking about it so how would I find it? PS. I put this in history because Indians first started this.
How much heat energy is produced by 0.5 Wh of electrical energy? A. 2.6 Btu B. 0.15 Btu C. 1.7 Btu D. 0.4 Btu
For half an hour the glass-bottomed boat drifted. Pitching and rolling above the reef in four- to six-foot waves. a. Fragment b. Run-on c. Correct
O que significa clima?
if juliet consistently buys health insurance for twenty years but never suffers a costly illness, were her premium payments wasted?
How many lines of symmetry does a regular quadrilateral have? a. 2 b. 4 c. 5 d. 6
tom has been given 35 chores to complete today. this morning he finished 7 of them. how many chores does he now have left to do?
what is the average of 64, 69, 73
Which one of these items is a nonrenewable resource? a. plant b. tree c. gasoline d. fish