Oct 19, 2012 at 5:18pm UTC
Hello, I'd like to know why is this not working
#include <iostream>
using namespace std;
int main()
{
double mark;
cout<<"Enter your mark = ";
cin>>mark;
if ( mark == 100 )
{
cout<<"You got a perfect score!\n";
}
else if (mark <= 59);
{
cout<<"You got F\n";
}
else (mark >=59);
{
cout <<"You got a B\n";
}
system("pause");
Last edited on Oct 19, 2012 at 5:21pm UTC
Oct 19, 2012 at 5:43pm UTC
Possibly missing a brace. Count the beginning braces { it must have a matching closing brace }.
Last edited on Oct 19, 2012 at 5:44pm UTC
Oct 19, 2012 at 5:45pm UTC
It's not missing anything
Oct 19, 2012 at 5:50pm UTC
As jlb said - It is missing a brace.
If you use an IDE, you can get to automatically do closing braces, parentheses, Square brackets etc.
Otherwise, get into the habit of typing both the opening & closing brace, then go back & fill in the code between.
Some other ideas:
Always use code tags - the <> button on the right
Post your compiler output.
Edit: As LowestOne says - indenting, you can get the IDE to do that too.
Last edited on Oct 19, 2012 at 5:52pm UTC
Oct 19, 2012 at 5:50pm UTC
Please use code tags (the <> button) around your code. Also, indent for every opening brace.
system("pause" );
is outside of main()
Oct 19, 2012 at 5:52pm UTC
Strange I count 4 opening braces { and only 3 closing braces }. Does your program compile without errors?
If you are getting errors, please post the complete error. If it does compile what are you inputting into your program, and what is your program outputting, and what do you expect the program to output?
Oct 19, 2012 at 5:53pm UTC
First of all use source code format when posting code. It makes it so much easier to read.
Second if you have code that isn't working, it's generally useful to post the errors you're receiving.
To fix this code:
you're missing a bracket for the last "else" statement
You don't put semi colons (;) after the declaration of statements (if, else etc.)
Don't use system("anything"). It is awful programming practice.
If you want the program to not close immediately, you can use cin.get()
else statements don't have arguments, so remove the (mark >=59)
The program should look something like this
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
#include <iostream>
using namespace std;
int main()
{
double mark;
cout<<"Enter your mark = " ;
cin>>mark;
if ( mark == 100 )
{
cout<<"You got a perfect score!\n" ;
}
else if (mark <= 59)
{
cout<<"You got F\n" ;
}
else
{
cout <<"You got a B\n" ;
}
cin.get()
}
Last edited on Oct 19, 2012 at 5:56pm UTC
Oct 19, 2012 at 6:08pm UTC
I understand, Thanks
I'll keep that system thing in mind too.