ok, so i'm trying to make 3 programs. Each takes a bunch of inputed numbers and spits up either (1) the highest number (2) the lowest (3) the average of all the numbers. The numbers must be <=100, and if it's not, the program should be able to produce the appropriate output without having to re-enter the values. So far, each program i've made just gives me either the first number I put in or randomly fails on me for no reason; I am absolutely stuck.
so here are my codes.
p.s. I do not want to end a sequence of inputs with '-1' but I can't get the program to work at all unless I do that. grrrr
1. averageCODE
#include <iostream>
using namespace std;
int main()
{
double sum = 0;
int count = 0;
bool more = true;
double score = 0;
while (score != -1)
{
cout << "Please enter the test scores; type '-1' to finish. ";
cin >> score;
if (score != -1)
{
sum = sum + score;
count++;
}
}
if (score <= 100)
cout << "The average test score is " << sum / count << "\n";
else
cout << "One of the values you have entered is greater than 100! \n";
return 0;
}
2. highestCODE
#include <iostream>
using namespace std;
int main ()
{
double next;
double highest;
cout << "Please enter the test scores: \n";
if (cin >> next)
highest = next;
else
{
cout << "No data!\n";
}
while (cin >> next)
{
if (next <=100)
highest = next;
}
while (next <=100)
{
if (next > highest)
highest = next;
}
cout << "The highest test score is " << highest << "\n";
return 0;
}
3. lowestCODE
#include <iostream>
using namespace std;
int main ()
{
double next;
double lowest;
cout << "Please enter the test scores: \n";
if (cin >> next)
lowest = next;
else
{
cout << "No data!\n";
}
while (cin >> next)
{
if (next <=100)
lowest = next;
}
while (next <=100)
{
if (next < lowest)
lowest = next;
}
cout << "The lowest test score is " << lowest << "\n";
return 0;
}
This post has been edited by miensta: 5 May, 2008 - 06:39 PM