### i want a help to solve this

Pages: 12
You are going to help me with a program that displays grade statistics. The
program should read any number of grades (up to 100) and ends when the user enters
-1, the program should reject any invalid grade. You should store the numbers in
an array
The program displays the following:
number of grades is even, the median is the average of the middle two
· The standard deviation, calculated as:
standard deviation=

(1/(N-1)*(i=0 to N Σ(xi-m)square))and all to the power 0.5 , where

m : the average of grades
N : the number of grades
· An error message if the user enters an invalid grade ( grade > 100 or grade
< 0).
Sure, we'd be happy to help with your homework, but we're not going to do it for you.

Let's start at the very basics: Write a program that reads grades entered by the user into an array.

You will need to:

* Create an array of a type that stores numbers, of a maximum size of 100.
* Create a loop that asks the user to input a grade, then checks if it is valid and if it is indeed valid, stores it in the array.

Come back to us with the code you have for that and then we'll start adding the other functions on top of that.

Please let us know if you require any further explanations.

All the best,
NwN
Last edited on
At-least show some progression, we might help you if you have any doubt or problem or an error.
sorry for my late to answer you
and no its nt a homework

my teacher gave it to me to improve myself in arrays and functions in c++
because im very very week( he didnt knw tht i dont understand because if he knew tht he will get mad) , he told if you wrote this program u will be good enough to write programs

and actully i dont understand arrays and functions, because that i registerd here
Hi there,

Quoting myself:

 You will need to: * Create an array of a type that stores numbers, of a maximum size of 100. * Create a loop that asks the user to input a grade, then checks if it is valid and if it is indeed valid, stores it in the array. Come back to us with the code you have for that and then we'll start adding the other functions on top of that.

You can find all the necessary information here:

http://cplusplus.com/doc/tutorial/basic_io/
http://cplusplus.com/doc/tutorial/control/
http://cplusplus.com/doc/tutorial/arrays/

At least try to come up with something - this is really very basic stuff.
If you need explanations about certain things, just ask us, but don't ask us to just give you the code, because we won't.

All the best,
NwN
 he told if you wrote this program u will be good enough to write programs

He's right, if someone does it for you, that isn't going to help you at all.

get busy
ok

how to write a function and what is the meaning of
( return x) or somthing like that
Here's a basic function below...

"aFunction" is the name of the function. It returns a value of type int (integer) which for example purposes I have just set to 1.

 ``12345`` ``````int aFunction() { int anInteger = 1; return anInteger; }``````

Here is how this function would be called in main displaying the number 1 on the screen:

 ``123456789`` ``````int main() { int whatNumber; whatNumber = aFunction(); cout << whatNumber; return 0; }``````
i stuck with sorting

i dont know how to sort in do while loop
and i dont know how to make the program reads and stores unknown size in array :/

#include<iostream>
using namespace std;
int main()
{
int c=0;
double avr=0,sum=0;
double x,max=0,min=100,h=0;
double A[];

do
{
cin>>x;

A[h]=x;

if(x>max&&x<=100)
{
max=x;
}
if(x<min&&x>=0)
{
min=x;
}

if(x<=100&&x>=0)
{
c++;
}
else if (x!=-1)
{

cout<<"try again";
}
h++;

}

while (x!=-1);
sum=sum+x;
avr=sum/c;
cout<<"avr = "<<avr<<endl;
cout<<"max number = "<<max<<endl;
cout<<"min number = "<<min<<endl;

return 0;
}
I think you're reading the instructions wrong, what you need to do is initialize double A[100]; because he wants the program to take any number of grades up to 100 student's grades.

There are some issues with your code besides that. you need to put "A[h] = x" inside of the if statement that tests whether the number is acceptable or not.

next try nesting a while loop in there that checks if a number is lower than the numbers entered before it and swaps them if it is.

simple sorting code;
 ``123456789101112`` `````` int holder = 0, i = 0;//place this next to the other variables that you declared above i = h; while(A[i] < A[i-1])//this will run until the number has been sorted into place { holder = A[i-1]; A[i-1] = A[i]; A[i] = holder; i --; } ``````
ohh i didnt notice ( up to 100 )

but how can i add while loop to my do while loop

while(A[i] < A[i-1])
{
holder = A[i-1];
A[i-1] = A[i];
A[i] = holder;
i --;
}

im sorry :( ... im nt good at all
Hi there,

 ``1234567`` ``````do { holder = A[i-1]; A[i-1] = A[i]; A[i] = holder; i --; } while(A[i] < A[i-1]);``````

For help on sorting, I just explained the use of the bubble sort algorithm to someone yesterday in this thread:
http://cplusplus.com/forum/general/89676/

Hope that helps.

All the best,
NwN
i tried

i dont know how to make the array and sorting numbers and all these in one loop

omg this the same homework i have to do hhhhhhh small world but cr8 reference site hhhhhhh i alrdy di the same topic xD .
if i write it i can help u if u want .
good luck
As Darkmaster already mentioned, if you are not required to write your own sort algorithm, just use the std::sort function:

 ``12`` ``````#include std::sort(A, A+100);``````

That would be all there is to it.

All the best,
NwN
i have to change do body and replace them with array

how to do that
and there is another problem

i want the average

so i write
sum=sum+x;
avr=sum/c;

but the the average ouput is wrong why ??!!
Try:

 ``123`` ``````for (int i=0;i<100;i++) sum+=A[i]; avr=sum/c;``````

Or use std::accumulate:

 ``12`` ``````#include sum = std::accumulate(A, A+100, 0);``````

All the best,
NwN
the ouput is nan ??????

here what i wrote

do
{
cin>>x;

if(x>max&&x<=100)
{
max=x;
}
if(x<min&&x>=0)
{
min=x;
}

if(x<=100&&x>=0)
{
c++;
}
else if (x!=-1)
{

cout<<"try again";
}
for (int i=0;i<100;i++)
{
sum+=A[i];
avr=sum/c;
}
}

while (x!=-1);

cout<<"avr = "<<avr<<endl;
cout<<"max number = "<<max<<endl;
cout<<"min number = "<<min<<endl;

return 0;
}
You're not thinking this through:

 ``123456`` ``````for (int i=0;i<100;i++) { sum+=A[i]; } avr=sum/c; //this needs to be outside the loop ``````

Also, please wrap the code in code tags: [code] code here [/code], that makes it more readable.

All the best,
NwN
Pages: 12