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

Urbanism is the way of life, patterns of behavior, and culture of city dwellers. True or False
according to Erikson's theory, which stage of social development is related to adulthood​
I need an easy concept to write about for an essay. It has to be about a time I was unfairly judged. (Can’t be about race or money)
4. Why did it prove to be so difficult for many African countries to establish strong, thriving economies following independence?
Factor completely 3x3 + 12x2 + 18x.
A person alive for x 3(2x-3)+4(2-x)=0 .. A. 1/2 B. 17/10 C. -17/2
A rectangular patio is 9 ft by 6 ft. When the length and width are increased by the same amount, the area becomes 88 sq ft. Ginger is using the zero product pro
Which of the following best states the difference between an alcohol and an ether? In an alcohol, a carbon atom is double bonded to an oxygen atom; in an ether,
In the 1800’s, Britain and the United States had laws against unionizing mainly because they believed unions...
3. Roads in urban areas are generally