Hi I am new to C++ programming and I have an assignment that has been driving me crazy for the past few days. The assignment is as follows...
Write a program with a loop that lets the user enter a series of integers, followed by -99 to signal the end of the series. After all the numbers have been entered the program will display the largest and the smallest numbers entered. After every series of numbers ask the user "Do you wish to continue (Y/N)?". If the answer is 'y' or 'Y' the program should continue asking for series of integers.
I am not sure exactly what I am supposed to do for this to work properly. Any help would be greatly appreciated!
#include <iostream>
#define EXIT -99
#define CONTINUE 1
usingnamespace std;
int smallest, largest, current;
int main() {
while (true) {
while (true) {
cout << "Number: ";
cin >> current;
if (current == EXIT) break;
smallest <?= current;
largest >?= current;
}
cout << "Smallest: " << smallest << endl;
cout << "Largest: " << largest << endl;
cout << "1 to continue, anything else to bugger off" << endl;
cin >> current;
if (current != CONTINUE) break;
}
return(0);
}
Also, a nested while() loop is not the greatest idea, but most people frown upon using goto statements. However, coming from a background in assembly language, I can safely say that goto will not kill your cat, or make your programs any worse.
This program would be more optimised, but you'll probably get caned by your teacher: