input user his/her grade

Im a newbie to this .. im having a hard time to solve whats the problem,



#include <iostream>
#include <string>

using namespace std;

int main ()
{

float grade[200];
string name[200];
int circle=0;
int repeat=0;
string display="";

cout<<"Enter number of students:"<<endl;
cin>>circle;

for(repeat=1; repeat<=circle; repeat ++)
{
cout<<"enter a name"<<endl;
cin>>name[repeat];

}
for(repeat=1; repeat<=circle; repeat ++)
{
cout<<"enter " <<name[repeat] <<" grade: "<<endl;
cin>>grade[repeat];



if(grade<=1.9 && grade >=1.0)
{
display= "***";
}
else if(grade<=2.9 && grade >=2.0)
{
display= "**";
}
else if(grade==3.0)
{
display= "*";
}
else{
display = "Invalid Input";
}
}

cout<<"output " << "Remark "<<endl;
for(repeat=1; repeat<=circle; repeat ++)
{
cout<<name[repeat]<< display[repeat]<<endl;
}

return 0;
}
Last edited on
What you probably want is to make display an array. Also, never test floating point numbers for equality as you've done with that 3.0.

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

using namespace std;

int main()
{
	float grade[200];
	string name[200];
	int circle=0;
	int repeat=0;
	string display[200];

	cout<<"Enter number of students:"<<endl;
	cin>>circle;

	for (repeat=1; repeat<=circle; repeat ++)
	{
		cout<<"enter a name"<<endl;
		cin>>name[repeat];
	}

	for(repeat=1; repeat<=circle; repeat ++)
	{
		cout<<"enter " <<name[repeat] <<" grade: "<<endl;
		cin>>grade[repeat];

		if(grade[repeat] <=1.9 && grade[repeat] >=1.0)
		{
			display[repeat] = "***";
		}
		else if(grade[repeat] <=2.9 && grade[repeat] >=2.0)
		{
			display[repeat] = "**";
		}
		else if(grade[repeat]==3.0)
		{
			display[repeat] = "*";
		}
		else
		{
			display[repeat] = "Invalid Input";
		}
	}

	cout<<"output " << "Remark "<<endl;
	for(repeat=1; repeat<=circle; repeat ++)
	{
		cout<<name[repeat]<< display[repeat]<<endl;
	}

	return 0;
}
Topic archived. No new replies allowed.