Answer to Question #155266 in C++ for LEEYAH

Question #155266

Allow the user to input two integers. Variables, Num1 and Num2 (Num1 must be less than Num2, values must be a positive number) (use loop); create a user-defined function to validate the users input.


1
Expert's answer
2021-01-14T09:19:49-0500
using std::cin;
using std::cout;
void user_input() {
  int first = 0, second = 0;
  bool good_input = false;
  while (!good_input) {
    cout << "Plese input two variables:\t";
    cin >> first >> second;
    if (first < second && first > 0 && second > 0) {
      good_input = true;
      cout << "Thank you!\n";
    } else {
      cout << "Please try again\n";
    }
  }
}

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