469,602 Members | 1,747 Online

# Need help with the grade program in functions 4
I need immediate help in writing a function program. I have to write a
program in functions and use array to store them. I am not familiar
with functions and i tried to create it but i fails to run, However, i
simply created this program in arrays and it runs good except i cant
figure out how to compute the standard deviation. The coding is below.
Any help will be appreciated.

1) The Program will prompt the user for six grades to be entered (one
at a time, read in each grade by the user , and them in an array of six
elements.

2) The average grade (again, on a 0.0 - 4.0 scale), by looping through
the array again;

3) The program will compute the standard deviation of the six
individual grades from the average according to following formula:

n-1
E (x[i] - avg)2
I=0___________________

n-1
where n is the number of values that were averaged (6 in this case),
x[i] is a particular value, and avd of all n values. I.e for each of
the n values, you take the difference between that value and the
average, square that difference, and sum all n squares. Then divid that
sum by n-1 and take the square root of that quotient. This gives you
the standard deviation.

#include <iostream>

using namespace std;

int main()
{
const int SIZE = 6;
double score[SIZE];
int i =0;
double sum = 0;

for ( i = 0; i < SIZE; i++)

{
cout << "Input a Score " << i+1 << ":" ;
cin >> score[i];

while (score[i] > 4 || score[i] < 0)
{
<< " between 0 and 4.0 inclusive : ";
cin >> score[i];
}
sum = sum + score[i];
}

double average = sum / 6 ;

if (average <= 4.0 && average > 3.2)
{
}
if (average <= 3.2 && average > 2.4)
{
}
if (average <= 2.4 && average > 1.6)
{
}
if (average <= 1.6 && average > 0.8)
{
}
if (average <= 0.8 && average > 0)
{
}

// Output the result:
cout << "The average is " << average << "." << endl;

cout << "The final letter grade is " << grade << endl;
return 0;
} // function main
Dec 9 '06 #1
1 3300 thefarmer
55 I need immediate help in writing a function program. I have to write a
program in functions and use array to store them. I am not familiar
with functions and i tried to create it but i fails to run, However, i
simply created this program in arrays and it runs good except i cant
figure out how to compute the standard deviation. The coding is below.
Any help will be appreciated.

1) The Program will prompt the user for six grades to be entered (one
at a time, read in each grade by the user , and them in an array of six
elements.

2) The average grade (again, on a 0.0 - 4.0 scale), by looping through
the array again;

3) The program will compute the standard deviation of the six
individual grades from the average according to following formula:

n-1
E (x[i] - avg)2
I=0___________________

n-1
where n is the number of values that were averaged (6 in this case),
x[i] is a particular value, and avd of all n values. I.e for each of
the n values, you take the difference between that value and the
average, square that difference, and sum all n squares. Then divid that
sum by n-1 and take the square root of that quotient. This gives you
the standard deviation.

#include <iostream>

using namespace std;

int main()
{
const int SIZE = 6;
double score[SIZE];
int i =0;
double sum = 0;

for ( i = 0; i < SIZE; i++)

{
cout << "Input a Score " << i+1 << ":" ;
cin >> score[i];

while (score[i] > 4 || score[i] < 0)
{
<< " between 0 and 4.0 inclusive : ";
cin >> score[i];
}
sum = sum + score[i];
}

double average = sum / 6 ;

if (average <= 4.0 && average > 3.2)
{
}
if (average <= 3.2 && average > 2.4)
{
}
if (average <= 2.4 && average > 1.6)
{
}
if (average <= 1.6 && average > 0.8)
{
}
if (average <= 0.8 && average > 0)
{
}

// Output the result:
cout << "The average is " << average << "." << endl;

cout << "The final letter grade is " << grade << endl;
return 0;
} // function main
hi there,

in your header put " #include <string.h>, and you do'nt have any declaration in your sum function, coz in your

code: sum = sum + score [i]; // how will you get the input "sum" i suggest to create some formula for it.

regards,
Dec 9 '06 #2

 35 posts views Thread by Henry | last post: by 4 posts views Thread by robinsand | last post: by 1 post views Thread by Theadmin77 | last post: by 21 posts views Thread by asif929 | last post: by 4 posts views Thread by sparkid | last post: by 10 posts views Thread by pythonnoob | last post: by reply views Thread by yjh0914 | last post: by 14 posts views Thread by xtheendx | last post: by reply views Thread by devgraph | last post: by reply views Thread by billypeterson | last post: by reply views Thread by Drake Tucker | last post: by reply views Thread by strativab | last post: by reply views Thread by devrayhaan | last post: by reply views Thread by neerajsundriyal | last post: by reply views Thread by Simmer | last post: by reply views Thread by gheharukoh7 | last post: by reply views Thread by tieutu2004 | last post: by