Ok i am right now working on a homework due tonight and need some help in figuring out how to take my grade averages and make them put in average.
The end product needs to take 10 numbers and average them. Can anyone help/ explain what is needed to create an average. I have spent time trying to figure it out but I am confused.
Final should do something like this:
Grade 1: 90
Grade 2: 86
Grade 3: 95
Grade 4: 76
Grade 5: 92
Grade 6: 83
Grade 7: 100
Grade 8: 87
Grade 9: 91
Grade 10: 0
Average Grade: 80%
#include <iostream> // for CIN and COUT
#include <cassert> // for ASSERTs
usingnamespace std;
/**********************************************************************
* main(): Simple demo program for looping through an array
***********************************************************************/
int main()
{
// Declare the variables
constint SIZE = 10; // this is a CONST so we are safe
int listDestination[SIZE]; // copy data to here
int listSource[SIZE]; // copy data from here
assert(SIZE == sizeof(listSource) / sizeof(listSource[0]));
assert(SIZE == sizeof(listDestination) / sizeof(listDestination[0]));
// Fill the list
for (int i = 0; i < SIZE; i++)
{
assert(i >= 0 && i < SIZE); // yes, I am paranoid
cout << "Grade " << i + 1 << ": "; // humans start counting at 1
cin >> listSource[i]; // computers start at 0
}
// Copy the list
for (int i = 0; i < SIZE; i++) // same loop we use for all arrays
{
assert(i >= 0 && i < SIZE); // very, very paranoid
listDestination[i] = listSource[i]; // copy one at a time
}
// Display the results
cout << "Average Grade: "
<< listDestination[0]; // display the first item
for (int i = 1; i < SIZE; i++) // standard loop skipping the 1st
{
assert(i > 0 && i < SIZE); // did I mention I am paranoid?
cout << ", " << listDestination[i]; // all the rest have a , before
}
cout << endl;
return 0;
}
#include <iostream>
usingnamespace std;
int main()
{
constint SIZE = 10;
int Grades[SIZE]; //*Why two arrays and copying?
int average; //*this will store our avarage
average =0;
for (int i = 0; i < SIZE; i++)
{
cin >> Grades[i];
average = average + Grades[i]; //*accumulates the total
}
average = average / SIZE; //*calculates the average value Total/SIZE
cout << average; //*prints the average
return(0);
}
Note that to just calculate the average value, all we would need is to accumulate, the array is never really used. Its just storing the values.
Of course afterwards you can be paranoid as much as you want :)
#include <iostream> // for CIN and COUT
#include <cassert> // for ASSERTs
usingnamespace std;
/**********************************************************************
* main(): Simple demo program for looping through an array
***********************************************************************/
int main()
{
// Declare the variables
constint SIZE = 10; // this is a CONST so we are safe
int listDestination[SIZE]; // copy data to here
int listSource[SIZE]; // copy data from here
assert(SIZE == sizeof(listSource) / sizeof(listSource[0]));
assert(SIZE == sizeof(listDestination) / sizeof(listDestination[0]));
// Fill the list
for (int i = 0; i < SIZE; i++)
{
assert(i >= 0 && i < SIZE); // yes, I am paranoid
cout << "Grade " << i + 1 << ": "; // humans start counting at 1
cin >> listSource[i]; // computers start at 0
}
int Grades[SIZE]; //*Why two arrays and copying?
int average; //*this will store our avarage
average =0;
for (int i = 0; i < SIZE; i++)
{
cin >> Grades[i];
average = average + Grades[i]; //*accumulates the total
}
average = average / SIZE; //*calculates the average value Total/SIZE
cout << average; //*prints the average
return 0;
}
#include <iostream>
usingnamespace std;
int main()
{
constint SIZE = 10; // this is a CONST so we are safe
int listDestination[SIZE]; // copy data to here
int listSource[SIZE]; // copy data from here
int Grades[SIZE]; //*Why two arrays and copying?
int average = 0; //*this will store our avarage
for (int i = 0; i < SIZE; i++)
{
cout << "Grade " << i + 1 << ": "; // humans start counting at 1
cin >> listSource[i]; // computers start at 0
}
for (int i = 0; i < SIZE; i++)
{
//cin >> Grades[i];
average = average + Grades[i]; //*accumulates the total
}
average = average / SIZE; //*calculates the average value Total/SIZE
cout << average;
cout << endl; //*prints the average
return 0;
}