help me

i try this code, and it keep on display an invalid number has been entered.
where did i do wrong?

#include<iostream>
using namespace std;
int main()
{
int numcred;

cout<<"enter the number of credits completed : ";
cin>>numcred;

if(numcred<32)

cout<<"level of grade equal to freshman"<<endl;

else if((numcred==32) && (numcred<=63))

cout<<"level of grade equal to sophomore"<<endl;

else if((numcred==64) && (numcred<=95))

cout<<"level of grade equal to junior"<<endl;

else if(numcred>=96)

cout<<"level of grade equal to senior"<<endl;

else
cout<<"an invalid number has been entered"<<endl;

return 0;
}
Hi,
1
2
3
4
5
6
else if((numcred==32) && (numcred<=63))
cout<<"level of grade equal to sophomore"<<endl;
else if((numcred==64) && (numcred<=95))
cout<<"level of grade equal to junior"<<endl;
else if(numcred>=96)
cout<<"level of grade equal to senior"<<endl;


==>

1
2
3
4
5
6
else if((numcred >= 32) && (numcred<=63))
cout<<"level of grade equal to sophomore"<<endl;
else if((numcred >= 64) && (numcred<=95))
cout<<"level of grade equal to junior"<<endl;
else if(numcred>=96)
cout<<"level of grade equal to senior"<<endl;
Does that help you? :)
5a8Ym39o6 gave you the solution i try to explain it.

If you use ...

else if((numcred==32) && (numcred<=63))

... the statement is only true for the entered value of 32, because of your == operator. You have to create intervals between a maximum and a minimum. So in your else-if-statement only values less than 32 can lead to a true statement. Any other number leads to your invalid number message.
Last edited on
owh i see. thanks for the reply.
it works ! thanks guys for the solution and explanation. it really helps me out.
Good to hear :)
Topic archived. No new replies allowed.