I wrote the following program with the instructions in the top comments: ( I am using visual studio on vista)
#include <iostream>
using namespace std;
int main()
{
int num1, num2;
int total = 0;
cout << "Please enter an integer between 0 and 100: ";
cin >> num1;
int numx = num1;
if (num1 < 0)
{
cout << "Please read and follow the directions!" << endl;
}
else if (num1 > 100)
{
cout << "Please read and follow the directions!" << endl;
}
else
{
cout << "Please enter an integer between 50 and 100: ";
cin >> num2;
}
while (num1 <= num2)
{
total = total + num1;
num1++;
}
if ((num1 >= 0) && (num1 <= 100) && (num2 >= 50) && (num2 <= 100))
{
cout << "The total of the integers between " << numx << " and " << num2 << " is " << total << endl;
}
else
{
cout << "Please read and follow the directions!" << endl;
}
}
I am having trouble: if the user enters a number less than 0 or greater than 100, the output needs to be "Please read and follow the directions!" And, the program should stop there. It should not go on to "Please enter an integer between 50 and 100." I am really stumped. Any help would be greatly appreciated.