Need a beginner program for college using some functions

closed account (G2UR4iN6)
So I'm using C++ and visual studio express and I'm a complete noob.
I was asked in college to do a small program.

The program has to do the following:
1- Tells the user to put the number of students.
2- To enter the grades of each of the students (out of 100).
3- Display the list of "pass" students (pass => 60) and their count.
4- Display the list of "fail" students and their count.

Use at least two types of loops from the following:
if/else, switch, while, do/while and for.

- Use 2 different selection types.
- Use arrays
- Use struct

If anyone can help, I'd appreciate it.
Please read
http://www.cplusplus.com/forum/beginner/1/

Then come and post what you have so far.
1
2
3
4
5
6
7
8
struct StudRecord
{
    string passOrFail;
    vector<int> studGrades; //Better because the size adjusts itself
};
cout << "num students? " << endl;
int numStudents;
cin >> numStudents;


Here is something i briefly wrote to help get you started. I can help more but you're gonna have to show some work too. Once you add to the code or write your own i can help further.
closed account (G2UR4iN6)
So this is what I did.

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
#include <iostream>
#include <cmath>
using namespace std;
int main()
{

	int students;
	int grades;

	cout << "Enter the number of students: ";
	cin >> students; // Type how many students are taking the course
	cout << "Enter the grades of each student: ";
	cin >> grades; /* I'm allowed to write one number.
Still don't know how can I write more than one number.
For example I'd like to write 100, 20, 27, 65 etc...
depending on how many students I wrote in the first input. */
	if (grades >= 60)
	{
		cout << "pass" << endl;
	
	}
	else {
		cout << "fail" << endl;
}
	if (students >=grades)
	{
		cout << "passed students " << students;
	}

	return 0;
}
closed account (G2UR4iN6)
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;
int main()
{
	
	int grade;
	char repeat = 'Y';

	while (repeat == 'y' || repeat == 'Y')
	{
		cout << "Enter the students grade: ";
		cin >> grade;

		if (grade <= 59)
		{
			cout << "The final grade is F." << grade << " Which is a fail." << endl;
		}
		else if (grade >= 60 && grade <= 64)
		{
			cout << "The final grade is D." << grade << " Which is a pass." << endl;
		}
		else if (grade >= 65 && grade <= 69)
		{
			cout << "The final grade is C-." << grade << " Which is a pass." << endl;
		}
		else if (grade >= 70 && grade <= 74)
		{
			cout << "The final grade is C." << grade << " Which is a pass." << endl;
		}
		else if (grade >= 75 && grade <= 79)
		{
			cout << "The final grade is C+." << grade << " Which is a pass." << endl;
		}
		else if (grade >= 80 && grade <= 84)
		{
			cout << "The final grade is B-." << grade << " Which is a pass." << endl;
		}
		else if (grade >= 85 && grade <= 88)
		{
			cout << "The final grade is B." << grade << " Which is a pass." << endl;
		}
		else if (grade >= 89 && grade <= 92)
		{
			cout << "The final grade is B+." << grade << " Which is a pass." << endl;
		}
		else if (grade >= 93 && grade <= 96)
		{
			cout << "The final grade is A-." << grade << " Which is a pass." << endl;
		}
		else if (grade >= 97 && grade <= 100)
		{
			cout << "The final grade is A." << grade << " Which is a Perfect score." << endl;
		}
		cout << "Do you wish to continue? (y/n)";
		cin >> repeat;
	}
}


I want the code at the end to type the number of passed and failed students after I press n when I'm asked do you wish to continue?

Example:

Number of passed students = 10
Number of failed students = 2
you need an int vector (or array) to store the grades in or else you are just rewriting over your grade variable.

1
2
3
4
5
struct StudRecord
{
    string passOrFail;
    vector<int> studGrades; //Better because the size adjusts itself
};


use this structure for student records. You can even add another string for name and this will hold all the data and it uses two structures as required by your teacher.

Also it isnt efficient to have all those if else statements. It will work but it is not professional.
for the number of pass and fail students simply put a counter within an if statement so whenever you add a fail grade the fail student variable will increment and vice versa for the pass students.
Topic archived. No new replies allowed.