469,602 Members | 1,747 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,602 developers. It's quick & easy.

Need help with the grade program in functions

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;
string grade;

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

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

while (score[i] > 4 || score[i] < 0)
{
cout <<" Invalid grade - please re-enter a grade"
<< " between 0 and 4.0 inclusive : ";
cin >> score[i];
}
sum = sum + score[i];
}

double average = sum / 6 ;


if (average <= 4.0 && average > 3.2)
{
grade = "A";
}
if (average <= 3.2 && average > 2.4)
{
grade = "B";
}
if (average <= 2.4 && average > 1.6)
{
grade = "C";
}
if (average <= 1.6 && average > 0.8)
{
grade = "D";
}
if (average <= 0.8 && average > 0)
{
grade = "F";
}

// 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
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;
string grade;

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

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

while (score[i] > 4 || score[i] < 0)
{
cout <<" Invalid grade - please re-enter a grade"
<< " between 0 and 4.0 inclusive : ";
cin >> score[i];
}
sum = sum + score[i];
}

double average = sum / 6 ;


if (average <= 4.0 && average > 3.2)
{
grade = "A";
}
if (average <= 3.2 && average > 2.4)
{
grade = "B";
}
if (average <= 2.4 && average > 1.6)
{
grade = "C";
}
if (average <= 1.6 && average > 0.8)
{
grade = "D";
}
if (average <= 0.8 && average > 0)
{
grade = "F";
}

// 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

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

35 posts views Thread by Henry | last post: by
4 posts views Thread by robinsand | last post: by
21 posts views Thread by asif929 | last post: by
reply views Thread by devrayhaan | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.