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

Davis has a bankruptcy on his credit report and therefore pays higher interest rates on her current loans. He took out a car loan for $45,000 payable for 6 year
Please help been struggling with this one and can’t seem to get it.
2. How can you specifically recognize chemical dependency in a friend or family member?
Is water access to water desalination equal across the region? Please answer! Thank you.
Which is an example of a physical change? (Select all that apply.) digesting food baking a cake melting snow boiling water
Hi May I know what is the answer and how to get it
How many acidic protons are there in 0.6137 g of KHP?
I want to cancel my subscription effective immediately !!!
The idea that the people have the right to abolish an abusive and unresponsive government was first said by Americans in the – Petition of Right Declaration of
Choose the number (X) that should come next in this series (1 4 9 16 X).