the program should generate two random numbers between 1 and 20 and display the first number. It should then ask the user to enter either H or L for Higher or Lower. The user wins if they entered H and the second number was higher than the first or when they entered L and the second number was lower.
#include <cstdlib>
#include <ctime>
#include <iostream>
using namespace std;
int main() {
srand((unsigned) time(0));
int a = (rand() % 20) + 1;
int b = (rand() % 20) + 1;
std::cout << "first number: " << a << std::endl;
std::cout << "Enter eihter H or L: " << std::endl;
std::string s;
std::cin >> s;
if (s == "H" and a < b or s == "L" and a > b)
std::cout << "You won!" << std::endl;
else
std::cout << "You loss!" << std::endl;
return 0;
}
Comments
Leave a comment