hello. I seem to be having a problem with my assignment. I am writing a program in which you enter scores for 20 different students and then the program displays the the highest, the lowest, and the average. I seem to be having a problem in my get highest that tells me that SIZE is undefined. I also have a problem in my get lowest loop telling me that my function is incompatible. my code is as follows. If anyone can help me, thank you!
#include <iostream>
using namespace std;
int getHighest(int [], int);
int getLowest(int [], int);
double getAverage(int [], int);
int count;
int numbers;
int main()
{
const int SIZE = 20;
int scores[SIZE];
double average;
int biggest, smallest;
for(int i=0; i<SIZE; i++)
{
cout << "Enter score for student: " << i+1 << ": " ;
cin >> scores[i];
while(scores[i] > 100 || scores[i] < 0)
{
cout << "Invalid score. Enter value between 0 and 100" << endl;
cin >> scores[i];
}
for(int i = 0; i < s; i++)
{
if (total[i] >biggest)
biggest = total[i];
}
return biggest;
}
//get min value
int getSmallest (int total[], int s)
{
int smallest;
for(int i = 0; i < s; i++)
{
if (total[i] < smallest)
smallest = total[i];
}
return smallest;
}
double getAverage(int ar[], int size)
{
double total= 0, avg;
for(int i=0; i<size; i++)
total += ar[i];
avg = total/size;
return avg;
}
My program compiles, but I have uninitialized local variables, "biggest" and "smallest" I am working towards fixing those, but if anyone can provide any input that would be very helpful
Please use code tags. Your code is hard to read without them.
[code]put your code here[/code]
Anyway this is the source of your problem:
1 2 3 4 5 6 7 8 9 10 11
int getHighest( int total[], int s)
{
int biggest; // you never give 'biggest' a value
for(int i = 0; i < s; i++)
{
if (total[i] >biggest) // so how can you compare against it here? What are you comparing to?
biggest = total[i];
}
return biggest;
}
You have the same problem with smallest in your other function.
//get maximum value
int getHighest( int total[], int s)
{
int biggest = 0;
for(int i = 0; i < s; i++)
{
if (total[i] >biggest)
biggest = total[i];
}
return biggest;
}
//get min value
int getSmallest (int total[], int s)
{
int smallest = 0;
for(int i = 0; i < s; i++)
{
if (total[i] < smallest)
smallest = total[i];
}
return smallest;
}
However I am now return 0 as my smallest value. Seems like a have an error in logic, since every score is being compared to 0, perhaps i should initialize 0 to a higher number?
yes thank You Disch lol. I changed the zero to a higher number and now have my code working as stated in the assignment
Thank you all for your help. this is my first experience with cplusplus.com and it was a good one. I look forward to learning more from you all in the future.