Alright(I've asked before, didn't get a clear answer), this program uses a sentinal controlled loop(-99) and calculates the greatest and least number of integers. Question is how I would output the series of integers.
#include <iostream>
using namespace std;
int main()
{
int num, greatest, least;
char doAgain;
do
{ cout << "This program lets you input a series of numbers and finds\nthe greatest and least values.\n";
cout << "Type in a value. -99 will finish the series.\n";
cin >> num;
if (num == -99)
cout << "\nNo values were entered, so there is no smallest and greatest value.\n";
greatest = num, least = num;
while (num != -99)
{
{if (num > greatest)
greatest = num;
else if (num < least)
least = num;
cout << "Enter another value.\n";
cin >> num;}
}
if (greatest != -99 && least != -99)
{ cout << "\nSmallest value: " << least << endl;
cout << "Greatest value: " << greatest << endl;}
cout << "\nWould you like to do this again?(Y/N)\n";
cin >> doAgain;
cout << endl;}
while (doAgain == 'y' || doAgain == 'Y');
return 0;
}
The integer num needs to be outputted before the greatest and least values are outputted. Having an unlimted number of integers, I can't use separate variables and so I'm have some trouble as to how to output the values.
I learned about using a loop to read data from a file like this
while (!inputfile.eof())
{ cout << numer << " ";
inputfile >> number; }
and was wondering if something like this could be used for the user input cin that I'm using. Or perhaps I need to rewrite the code in a different way?
Anything in a more simple form? (My compiler is having a problem with line 11 btw) My programs aren't going to be that advanced right now and I haven't learned the vector headline either : /
I'm trying to use it as a guide line but there's too many new words that I don't know and that the class hasn;t gone over, I don't think something this "off track" would work. I was hoping someone could explain how I could use the data statement I mentioned above and use it with cin. My instructor said its possible and I'm not finding anything in the book on how to do that.