- Jul 14, 2005
- 988
- 0
- 76
Ok i can get this to function but Im wondering about how I can loop it all. This is an example of the outpout that needs to be asked:
Enter the ID for student 1: 1232
Enter the 1st test grade for student 1: 80
Enter the 2nd test grade for student 1: 65
Enter the 3rd test grade for student 1: 90
Enter the ID for student 2: 9821
Enter the 1st test grade for student 2: 30
Enter the 2nd test grade for student 2: -1
Invalid score! Enter a score between 0 and 100.
Enter the 2nd test grade for student 2: 22
Enter the 3rd test grade for student 2: 12
this goes all the way up to 35 students. My problem is with how to place the loops. this is what I got so far for coding. (im a NOOB). I just wanted to make sure I was going the right route and maybe just need to position it a little different. I am using an a, b, c, d array to hold the ID and the test scores. Thanks guys
for(int i=0;i<SIZE;i++){
do{
cout<<"Enter the ID for student "<<y<<" : ";
cin>>a;
if(a<1000||a>=9999){
cout<<"Invalid ID! Please enter a number between 1000 and 9999"<<endl;
y=y;
}
do{ cout<<"Enter the 1st test grade for student "<<y<<" : ";
cin>>b;
if(b<0||b>=100){
cout<<"Invalid score! Enter a score between 0 and 100."<<endl;
y=y;
}
y++;
}while(y>=1&&y<=35);
}
Enter the ID for student 1: 1232
Enter the 1st test grade for student 1: 80
Enter the 2nd test grade for student 1: 65
Enter the 3rd test grade for student 1: 90
Enter the ID for student 2: 9821
Enter the 1st test grade for student 2: 30
Enter the 2nd test grade for student 2: -1
Invalid score! Enter a score between 0 and 100.
Enter the 2nd test grade for student 2: 22
Enter the 3rd test grade for student 2: 12
this goes all the way up to 35 students. My problem is with how to place the loops. this is what I got so far for coding. (im a NOOB). I just wanted to make sure I was going the right route and maybe just need to position it a little different. I am using an a, b, c, d array to hold the ID and the test scores. Thanks guys
for(int i=0;i<SIZE;i++){
do{
cout<<"Enter the ID for student "<<y<<" : ";
cin>>a;
if(a<1000||a>=9999){
cout<<"Invalid ID! Please enter a number between 1000 and 9999"<<endl;
y=y;
}
do{ cout<<"Enter the 1st test grade for student "<<y<<" : ";
cin>>b;
if(b<0||b>=100){
cout<<"Invalid score! Enter a score between 0 and 100."<<endl;
y=y;
}
y++;
}while(y>=1&&y<=35);
}
