Whoops, another input problem

chizzain (39)
How do I make it so when the person enters a Test Score it only lets them enter a number 1-100?

Here is my code:
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
#include <iostream>
#include <string>  //String
#include <stdio.h>
#include <conio.h>

using namespace std;
class student
{
private :
	int sno;
	string name;  
	int g1,g2,g3,g4;
	int absen;
public :
	void Getdata()
	{
		cout << "Enter Student ID:  " << endl; 
		cin >> sno;
		cout << "Enter Student NAME:  " << endl;
		cin.get(); 
		getline(cin, name); 
		cout << "Enter Student TEST SCORES (3):  " << endl;
		cin >> g1 >> g2 >> g3;
		cout << "Enter # of Absences:  " << endl;
		cin >> absen;
	}
	void Putdata()
	{
		cout  << "Student ID:  " << sno << endl;
		cout << "Student NAME:  " << name << endl;
		cout << "# of Absences:  " << absen << endl;
		if (absen == 0) {
  g4 = 2;
} else {
  g4 = 0;
}

cout << "Grade:  " << (g1+g2+g3 + g4)/3 << endl;
		if ((((g1+g2+g3 + g4)/3) >= 73))
		cout << "Grade:  " << (g1+g2+g3)/3 << endl;
		if ((((g1+g2+g3)/3) >= 73))
		{cout << "Successful" << endl;}
		else
		{cout << "Unsuccessful" << endl;}
	};
};


int main()
{
	student s;
	s.Getdata();
	s.Putdata();
	getch();
	return 0;
}
Last edited on
Registered users can post here. Sign in or register to post.