please anyone just tell me how to right this litttle function??!!

function next_garde to generates 20 random exam grades (between 20 and 100
, and 60 is the passing grade). For each failing student, the program calls a function add10 that adds 10 points to try to pass the student (only for failing students). The program counts the number of passing students and the grade average before and after the curve using a function avg_pass and does the same for failing students using a function avg_fail.

i don`t know how to right this one!!

it always gives an error...

please help asap

thanks

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28

#include <iostream>

using namespace std;


#include <cstdlib>
#include <ctime>

using namespace std;

int next_grade()
{
int num;
int count = 1;
unsigned seed = time(0);

srand(seed);

while(count <= 1)
{
num = 20 + rand() % 80;
cout <<"the number is: "<< num <<" ,\t";
count++;
}

return num;
}
please i`m hopless ..really!!
Instead of declaring "num" in your function you should create an array "num" and pass it to your function as a pointer next_grade(num); and you will get an array of 20 random numbers. (you weren't using an array in your code, so it couldn't work)

Also I replaced while loop with for loop for simplicity and set condition to "count < 20", because your "count <= 1" would only be executed once.

1
2
3
4
5
6
7
8
9
10
11
void next_grade(int * num)
{
    unsigned seed = time(0);
    srand(seed);

    for(int count = 0; count < 20; count++)
    {
        num[count] = 20 + rand() % 80;
        cout <<"the number is: "<< num <<" ,\t";
    }
}


And your title should be "how to WRITE this LITTLE function?". Just some spelling fixes.
ayyy~~~ sorry!!!


this is what i got and it stopes fuctioning??



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include <iostream>

using namespace std;


#include <cstdlib>
#include <ctime>

using namespace std;

int next_grade()
{

int grade;
int p_grade=0;
int f_grade=0;
double avg_pass;
double avg_fail;
int pass=0 , fail=0;
int i;

unsigned seed = time(0);

srand(seed);

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

{

grade = 20 + rand() % 80;

if (grade >= 60)
{ 	

	p_grade = p_grade + grade; 
pass++;

}

else if (grade< 60)
{

f_grade= f_grade + grade;
fail++;

}

avg_pass = p_grade/pass;
avg_fail = f_grade/fail;

cout<<" average pass: "<< avg_pass <<endl;
cout<<" average fail: "<< avg_fail <<endl;
}

return grade;
}



don`t know nothin bout computers i really don`t know!!

zoran404
i really don`t know how to start!!!

please if you can be nice and help me just write this function and i can do rest by myself!!

please please :`(
Last edited on
Please use the next_grade function as I give to you and write the rest of the code in your main function.

Also, in your new code, the following code should not be inside your for loop, but after it:

1
2
3
4
5
avg_pass = p_grade/pass;
avg_fail = f_grade/fail;

cout<<" average pass: "<< avg_pass <<endl;
cout<<" average fail: "<< avg_fail <<endl;
And this is how to use arrays:

1
2
int num[20];    // 20 numbers
cout << num[0]; // show the first number 


Hope this helps.
thanks a lot zoran404 i`ll try my best
When there is an operating system (which is most cases), where does a C++ program start? [Hint: main()] You original post does not show that starting point. Start by showing that part even if it does little or nothing.

Here is some pseudo code which should get you started in the right direction:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27

set the four counts mentioned below to 0
set the four sums mentioned below to 0

for each student
	calculate a random grade
	if grade is a pass  // student passes
		increment passing student count
		accumulate grade into passing student sum
	else // student fails
		increment failing student without curve count
		accumulate grade into failing student uncurved sum
		add 10 points to failing student grade
	if grade is now a pass
		increment curved passing student count
		accumulate curved grade into curved passing student sum
	else
		increment curved failing student count
		accumulate curved grade into curved failing student sum
end of for each student		

// It is not clear which averages the problem statement calls for
// Display whichever are required by the problem statement.
display uncurved passing student average
display uncurved failing student average
display curved passing student average
display curved failing student average


I am not convinced that you are understanding the basics. So my suggested steps are below. At whichever step you have a problem, show your code and what error messages you received if any.

Write a program that does NOTHING but does compile, link, and execute.
Then do a program that creates and displays the student grades.
Then do a program that just averages the student grades.
Then do a program that averages the passing grades and failing grades without any adjustment.
Last edited on
Topic archived. No new replies allowed.