user input

how would I ignore an input if the user dont put one for GPA,ACT or SAT

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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
 using namespace std;
#include <iostream>
#include <string>
class Student
{
public:
	void output( );
	string FirstName;
	string LastName;
	double GPA;
	double ACT;
	double SAT;
};



int main()
{
	Student record,recordto;
	int choice;
	cout << "would you like enter 1 or 2 student data?";
cin >> choice;
	cout << "please enter student data:";
		

		
		if (choice == 1)
		{
			cout << "Please enter first name:";
			cin >> record.FirstName;
			cout << "Please enter Last name:";
			cin >> record.LastName;
			cout << "Please enter GPA grade:";
			cin >> record.GPA;
			cout << "Please enter ACT grade:";
			cin >> record.ACT;
			cout << "Please enter SAT grade:";
			cin >> record.SAT;
			system("cls");
			cout << "Student Record: \n" << "FirstName:\n" << record.FirstName << "\n" << "LastNeame:\n" << record.LastName << "\n" << "GPA:\n" << record.GPA << "\n" << "ACT:\n" << record.ACT << "\n" << "SAT:\n" << record.SAT << "\n" << "Test scores rating:\n", record.output();
		}
			
		if (choice == 2)
		{
			cout << "Please enter first name:";
			cin >> record.FirstName;
			cout << "Please enter Last name:";
			cin >> record.LastName;
			cout << "Please enter GPA grade";
			cin >> record.GPA;
			
			cout << "Please enter ACT grade:";
			cin >> record.ACT;
			cout << "Please enter SAT grade:";
			cin >> record.SAT;
			system("cls");
			cout << "Please enter first name:";
			cin >> recordto.FirstName;
			cout << "Please enter Last name:";
			cin >> recordto.LastName;
			cout << "Please enter GPA grade:";
			cin >> recordto.GPA;
			cout << "Please enter ACT grade:";
			cin >> recordto.ACT;
			cout << "Please enter SAT grade:";
			cin >> recordto.SAT;
			system("cls");
			cout << "Student Record: \n" << "FirstName:\n" << record.FirstName << "\n" << "LastNeame:\n" << record.LastName << "\n" << "GPA:\n" << record.GPA << "\n" << "ACT:\n" << record.ACT << "\n" << "SAT:\n" << record.SAT << "\n";
			cout << "Student Record 2: \n" << "FirstName:\n" << recordto.FirstName << "\n" << "LastNeame:\n" << recordto.LastName << "\n" << "GPA:\n" << recordto.GPA << "\n" << "ACT:\n" << recordto.ACT << "\n" << "SAT:\n" << recordto.SAT << "\n";

		}
		return 0;
}
void Student::output()
{
	//gpa
	if (GPA == 4){cout << ("GPA score is amazing\n");}

	if (GPA == 3 && GPA < 4){cout << ("GPA score is good but could improve\n");}
		
	if (GPA == 2 && GPA < 3){cout << ("GPA score is decent and the student needs to study to improve\n");}
		
	if (GPA == 1 && GPA < 2){cout << ("GPA score is a barely passing score and the student really needs to study to improve\n");}

	if (GPA == 0 && GPA < 1) { cout << ("GPA score is bad and the student failed and really needs to study to improve\n"); }

	//act	
	if (ACT == 36) { cout << ("ACT score is amazing\n"); }

	if (ACT == 33 && ACT < 36) { cout << ("ACT score is good but could improve\n"); }

	if (ACT == 20 && ACT < 33) { cout << ("ACT score is decent and the student needs to study to improve\n"); }

	if (ACT == 1 && ACT < 20) { cout << ("ACT score is bad and the student really needs to study to improve\n"); }
	if (ACT == 0 && ACT < 1) { cout << ("ACT score is bad and the student failed and really needs to study to improve\n"); }
	//SAT	
	if (SAT == 1600) { cout << ("SAT score is amazing\n"); }

	if (SAT == 1400 && SAT < 1600) { cout << ("SAT score is good but could improve\n"); }

	if (SAT == 1000 && SAT < 1400) { cout << ("SAT score is decent and the student needs to study to improve\n"); }

	if (SAT == 1 && SAT < 1000) { cout << ("SAT score is bad and the student really needs to study to improve\n"); }
	if (SAT == 0 && SAT < 1) { cout << ("SAT score is bad and the student failed and really needs to study to improve\n"); }

	}





		
Hello imthekingbabyz,

To answer your question, No.

By using cin >> you have to enter something. You can not just press enter to pass it. Therefore the least you could enter is a zero. And deal with it later if needed.

The first potential problem I see is line 1. I am not sure if that would the "#include"s that follow. I have always seen line 1 follow the "#include"s. Any way it is best not to use line 1 in the first place.

By placing all the variables in the class in "public" you are defeating the point of the class and might as well use a struct.

The class would be better as:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
class Student
{
    public:
        Student();  // <--- Default ctor and dtor.
        ~Student();

	void output( );

    private:
	string FirstName;
	string LastName;
	double GPA;
	double ACT;
	double SAT;
};


I do have a suggestion when you enter for the first and last names "std::getline" would work better. std::cin >> will only extract from the input buffer up to the first white space or new line whichever comes first. Then the next std::cin >> will extract what is left in the input buffer with out waiting for keyboard input. This will cause a problem.

Using "std::getline" will require the last "cin >>" to be followed with std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n'); // <--- Requires header file <limits>.

I do not know what the idea of this program is for. If it is for testing the input then I would not put much more into fixing it. If you want to enter more than two students then the program needs reworked or it will get very large very fast.

Hope that helps for now,

Andy
For that last part with all the ifs, couldn't you have done a switch statement? One for GPA, ACT and SAT?
the conditional area is a mess. if (x is an exact value and x is less than some other value) makes no sense.

you should have some strings :
score is amazing
score is good
score is terrible
etc and insert the test type in front of it to get
act score is amazing
sat score is good
gpa score is terrible

like that. factor out the common strings.
then you need to seriously simplify the logic. Maybe normalize it to a percentage of the max.
eg gpascore/= 4.0 (assuming 4.0 == 100%), satscore /= 1600, etc. then use the percents to generate the text, would that work?
Last edited on
Topic archived. No new replies allowed.