Answer to Question #208179 in C++ for toxic

Question #208179

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.


1
Expert's answer
2021-06-18T02:54:27-0400
#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;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS