hey everyone am new here and i just need your help in some code . i need a program to input five student grades in five subjects and if the student passes them all (pass mark 50 out of 100)it outputs "pass" and if he failed in one subject it out puts "warning 1" and if he failed 2 subjects it outputs "warning 2" and if he failed 3 or more it out puts "dismiss" i started by this way but it don't feel right .
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
#include <iostream.h>
#include <conio.h>
int main ()
{
int a,b,c,d,e;
cin>>a>>b>>c>>d>>e;
if ((a>=50)&&(b>=50)&&(c>=50)&&(d>=50)&&(e>=50))
{
cout<<"pass";
}
if ((a<50)&&(b>=50)&&(c>=50)&&(d>=50)&&(e>=50)||(a>=50)&&(b<50)&&(c>=50)&&(d>=50)&&((e>=50)||
(a>=50)&&(b>=50)&&(c<50)&&(d>=50)&&(e>=50)||(a>=50)&&(b>=50)&&(c>=50)&&(d<50)&&(e>=50)||
(a>=50)&&(b>=50)&&(c>=50)&&(d>=50)&&(e<50))
{
cout<<"propation2"<<endl;
}
getch();
return 0;
can you use structs/classes?
From what i understand from your post, you have 5 students each with 5 subjects.
You need to go through each of the subjects and chceck if the grades are above 5.
You could use a for loop to go through each of the subjects. You use a variable to count the failed subjects. If a subject is below 50 you increase this
you then check if this counter variable is greater then 3. If it is you break out of the for loop and print dismiss and finish the program or go to the next student
if not you continue with the for loop.At the end you use a switch
if the counter is 0 you print pass, if counter is 1 you print warning, and if it's 2 you print warning 2.
For the default you could print an error message since the counter shouldn't get any other values :)
after the switch you go to the next student.
Try and code something along this lines and post it here if you stil have dificulties.
If not while. While will keep adding forever since no break
For the output messages I would suggest a switch so its three output messages instead of 4 and less lines than doing else if