C++ averages

Ok, im reletivly new to c++ and i need help. I am trying to create a program in which the user is propted to enter the number of tests he wishes to calculate the average of then he enter the test marks and the system will calculate the average and display a message after the test depending on the grade.

*Note below i tried doing it but it didn't work, i don't know what to do i need help.

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
#include <cstdlib>
#include <iostream>
#include <string>

using namespace std;

int main()
{
	//  Declaration of Variables and Constants

	int tests;
	double average;
	double counter;

	// Input

	cout << "Class Average" << endl;
	
	cout <<" " << endl;

	cout << "How many tests do you want to enter: ";
	cin >> tests;

	for (int counter = 1; counter = tests; counter = counter +1)
	{;
		average = counter / tests;
		
		cout << "Please enter test " << ;
		cin >> counter;
	}
Last edited on
Last edited on
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
#include <cstdlib>
#include <iostream>
#include <string>

using namespace std;

int main()
{
	//  Declaration of Variables and Constants

	int tests;
	int counter;
	double average=0;

	// Input

	cout << "Class Average" << endl;
	
	cout <<" " << endl;

	cout << "How many tests do you want to enter: ";
	cin >> tests;
    int array[tests];
    
	for (counter=0;counter<=tests-1;counter++)
	{
	cout << "Please enter test score: ";
	cin >> array[counter];
	average+=array[counter];
	}
	
	average/=counter;
    cout<<"The average of the test scores entered is: "<<average<<endl;
	
	if(average>85)
	cout<<"The class average is excellent."<<endl;
	else if(average>=70&&average<=84)
	cout<<"The class average is good."<<endl;
	else
	cout<<"No comment"<<endl;
}
Thanks Cody
There's a few things that need to be said..

1)You posted this question before last night (http://www.cplusplus.com/forum/beginner/119944/) and you never really gave us the issue. In this post you failed to mention the fact that this is your homework.

2) Cody0023: You have changed his code quite a bit and pretty much gave him the answer. Please don't do this. Luckily he can't use the code anyways because..

3) moodle: You will most likely get a lot of points taken off for Cody's code because you would be using thing you probably haven't already learned, AND it's a form of cheating in most classes..

--"Write a “Class Average” program using a for loop that reads in the test marks for each student in a class and displays the average mark for the class. To create this program, please follow the steps below:
• Before the for loop:
o Declare and initialize the needed variables.
o Display the title of the program: Class Average
o Prompt the user for the number of tests that they wish to enter.
• Do the following Inside the for loop:
o Prompt the user to enter the mark test #1 where the value 1 is obtained from the variable that you initialize in your for loop.
o Sum the test marks.
• After the loop, display the following:
o The class average.
o If the class average is 85 or above, display the message “The class average is excellent”.
o If the class average is between 70 and 84, inclusive, display the message “The class average is good.”
o Otherwise display the message “No comment.”

Formulas: Average = Sum of the Marks / Number of Tests

Data Types: Use the integer data type for the count of the number of tests, and the double data type for the marks.


Output: This program’s output should look similar to:

Class Average

How many tests do you want to enter? 4

Enter the mark for test #1: 70
Enter the mark for test #2: 65
Enter the mark for test #3: 80
Enter the mark for test #4: 95

The average mark for the tests is 77.50
The class average is good."--


4) Your instructions pretty much tell you your entire code in bulletin form.

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
int main()
{

    // declare and initialize variables
    // display title of program
    // prompt for number of tests

     for(initialization; conditions; increase)
    {
         // Prompt user
         // Sum test marks
    }

    // display class average

    if(conditions)
    {
        //Display Message
    }
    else if (conditions)
    {
        //Display Message
    }
    else
    {
        //Display Message
    }

    return 0;
}


I just laid it out for you, and all I did was look at the bulletins your teacher gave you and went down the line.
Last edited on
Topic archived. No new replies allowed.