I appreciate any help anyone is willing to provide. I am trying to solve the following problem.
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 should display the largest and smallest numbers entered.
Below is my code. The wants to make the minimum number negative and the max a positive. If min/max are anything other than a -/+ then it gives me so off the wall number.
once again thank you for your help.
#include <iostream>
using namespace std;
int main()
{
//Declares a double variables
double number,max, min;
int sentinal = -99;
//for loop to calculate Calories Burned
while (number != sentinal)
{
//Ask user to input number
cout<< "Enter your number" << endl;
cout<< "Enter -99 if you have finished" << endl;
cin>> number;
if (number == sentinal)
break;
else if (number >= max)
{
max >= 0 || max <= 0;
max = number;
}
else if (number <= min)
{
min >= 0 || min <= 0;
min = number;
#include <iostream>
#include <iostream>
usingnamespace std;
int main()
{
//Declares a double variables
double number=0,max=0, min=0;
int sentinal = -99;
int count = 0;
//for loop to calculate Calories Burned
while (number != sentinal)
{
//Ask user to input number
cout<< "Enter your number" << endl;
cout<< "Enter -99 if you have finished" << endl;
cin>> number;
if (count == 0) min = number;
count++;
if (number == sentinal)
break;
elseif (number >= max)
{
max >= 0 || max <= 0;
max = number;
}
elseif (number <= min)
{
min >= 0 || min <= 0;
min = number;
}
else
{
max = max;
min = min;
}
}
cout<< max << "\t\t" << min <<endl;
system("PAUSE");
return 0;
}
Lines 24 and 29 don't make sense, the else on line 32-36 is useless, and since you use a break inside the while the condition is redundant.
Comparison for equality with floating point numbers should never be done.
I'd also suggest to check if (number > max) and (number < min). FIrst because of floats equality again, second because you don't really need to change the value of a variable if that value is identical to the previous.
Another thing. You should put max and min at a specificated value which is not 0, because the user can also insert only negative numbers, or only positive. My advice is
float max=-100; (just because if you put in -99 the cycle finishes)
float min=100000 (a big number, you should initialize to the maximum value, which is 3.4 x 10 ^34, if I remember right, but it doesn't matter)
then... if it's not compulsory, avoid using float
Happy easter everyone (sorry for my English)