Hi people..Can any1 help me with this?

i'm trying to figure out how to use if/else.I have try to compile a program i wrote and it keep giving me error on if.Here is the code i wrote:


#pragma hdrstop

//---------------------------------------------------------------------------

#pragma argsused
#include <iostream.h>
#include <conio.h>
main()

{
float grade1,grade2,result,exam,test,ID;

cout<<"Insert student ID :";
cin>>ID;
cout<<"Insert test mark :";
cin>>test;
cout<<"Insert examination mark :";
cin>>exam;

grade1 = test / 100 * 40;
grade2 = exam / 100 * 60;

result = grade1 + grade2;

cout<<"Student with ID number :"<<ID<<" obtains :"<<result;

if <-- I need help on this part please..thx.
{
result >= 80;
cout<<"A";
}
if else
{
result >=70;
cout<<"B";
}
if else
{
result >=60;
cout<<"C";
}
if else
{
result >=50;
cout<<"D";
}
if else
{
result >=0;
cout<<"F";
}



cout<<"\n";

getch();

return 0;
}
//---------------------------------------------------------------------------



can any1 help me out?? really appreciate it..

sorry i didnt put in the error i get..here is the error msg:


Error HMMM.CPP 27: If statement missing ( in function main()


i'm using borland C++ program..
Last edited on
I'm also just a beginner but why do you use if else? I think I see it.

the code u use with if should be (im just taking the first if line as reference)
1
2
if (result >= 80)
cout << "A";
what error are you getting?
Well, as M562 pointed out your "if" statements are malformed. Looks like you need to bone up on its proper implementation. Also youre using the the "if else statement", Im pretty sure that youre trying to implement the "else if statement", Im not sure if the other one even exist. Lastly, you use a couple of header files ie #include<>'s and thats ok. However, I think they are unneccesary to this particulare program unless this isnt the complete code. My motto.. more code, more complex to read, more of a pain to debug.:)
But it may be a prerequisite for your particular compiler, if so, just forget this last part. However, it maybe worth it to you to give using less header files a try at some point.
Well, as M562 pointed out your "if" statements are malformed. Looks like you need to bone up on its proper implementation. Also youre using the the "if else statement", Im pretty sure that youre trying to implement the "else if statement", Im not sure if the other one even exist. Lastly, you use a couple of header files ie #include<>'s and thats ok. However, I think they are unneccesary to this particulare program unless this isnt the complete code. My motto.. more code, more complex to read, more of a pain to debug.:)
But it may be a prerequisite for your particular compiler, if so, just forget this last part. However, it maybe worth it to you to give using less header files a try at some point.
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
if 
{
result >= 80;
cout<<"A";
}
else if
{
result >=70;
cout<<"B";
}
else if
{
result >=60;
cout<<"C";
}
else if
{
result >=50;
cout<<"D";
}
else
{
result >=0;
cout<<"F";
}


try this instead
ok M562 is right.I put the code like that and seems like there is no error.But i want to know for the other part (B,C,D,F) should i use 'if' also or i can use 'else'? and if i use 'else' how should i put it in code?

i'm really2 appreciate it.Thx M562 and others who help me out ^^
Last edited on
hi!
this code is about if-else statement cause each sentence is excuted only if the previous in no far true, that me the student ll get "A" if s/he result is grater then or equal to 80, otherwise "B" if s/he s result is less then 80 and greater then or equal 70 and so on, and what chemera did is the right
:)
hello.. i think kia is right...=)
Hello friends.
@Rediwan
It seems like you got it correct. The way M562 wrote the if statement is the proper way. You always have to put the condition in the ()'s. And your "if else" statements needed to be reversed to "else if" as demonstrated below. Good luck!
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
if (result >= 80){
cout<<"A";
}
else if (result >=70){
cout<<"B";
}
else if (result >=60){
cout<<"C";
}
else if (result >=50){
cout<<"D";
}
else if (result >=0){
cout<<"F";
}
yes kyleepparddtcom of course the condition should be in the () cause this is what ll let u have the result which is one of the output. as i mentioned earlier . :).
Topic archived. No new replies allowed.