PracticeDev/study_cpp/cpp_primer_source_code/Chapter 6/ifelseif.cpp

24 lines
559 B
C++
Raw Normal View History

2022-12-20 17:31:11 +08:00
// ifelseif.cpp -- using if else if else
#include <iostream>
const int Fave = 27;
int main()
{
using namespace std;
int n;
cout << "Enter a number in the range 1-100 to find ";
cout << "my favorite number: ";
do
{
cin >> n;
if (n < Fave)
cout << "Too low -- guess again: ";
else if (n > Fave)
cout << "Too high -- guess again: ";
else
cout << Fave << " is right!\n";
} while (n != Fave);
// cin.get();
// cin.get();
return 0;
}