Grading System..stuck at on point

closed account (ohUS216C)
Hey Peace up on you all =)
am stuck at some point in this code
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
26
27
28
29
# include <iostream.h>
void main()
{
	
char x[60];
int y;

cout<< "((use - Between the first and last name. No Space)"<<endl<<"Please Write The Student's Name:";
cin>> x ;

cout<< "Please Enter the Grade Number Of "<<x<<": ";
cin>> y;

if (y>=85){
cout<<"Excellent"<<endl;
}
else if (y<85||y>=75){
cout<<"Very Good"<<endl;
}
else if (y<75||y>=65){
cout<<"Good"<<endl;
}
else if (y<65||y>=50){
cout<<"Pass"<<endl;
}
else { (y<50);
cout<<"fail"<<endl;
}
}



when you run this code
and write any number lower than "75"
you still get "Very Good",
i watched a tutorial for "If"
Url: http://www.youtube.com/watch?v=Fcc8lWmd01Y&feature=related
but still couldn't figure it out.


please try not to write the answer but give me hints
because i wanna solve it with myself =).
Thank you =)
Hint: iostream.h and void main are abominations.
Hint2: Uh... don't use middle alignment. It's hard to read.

Anyways... look at your conditions, and write down in words what they mean. You should see your problem then. And don't watch video tutorials, most of them are crappy. Read the tutorials on this site instead. http://www.cplusplus.com/doc/tutorial/
closed account (D80DSL3A)
Hint: The || (logical or) isn't doing what you may be thinking here. || evaluates to true if EITHER condition is true. You need BOTH conditions to be true.
It is called logic overload / short circuiting ;)
closed account (ohUS216C)
DONE!!!! Thx Guys For Helping =D
i switched from || (or) TO &&(and) and it worked
i know its my bad but still am beginner =)
Thx fun2code =)
Thx hanst99 i will just when am done with my course
but why it is abomination??
iostream.h is deprecated since years (I am pretty sure at least since the 90s), and main should always return an int - modern compilers would simply refuse to compile a void main function.
You can actually even remove the first portion since you are using 'else if' statements (only 1 condition can be true).

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
26
# include <iostream>
using namespace std;

int main()
    {
    char x[60];
    int y;

    cout<< "((use - Between the first and last name. No Space)"<<endl<<"Please Write The Student's Name:";
    cin>> x ;

    cout<< "Please Enter the Grade Number Of "<<x<<": ";
    cin>> y;

    if (y>=85)
        cout<<"Excellent"<<endl;
    else if (y>=75)
        cout<<"Very Good"<<endl;
    else if (y>=65)
        cout<<"Good"<<endl;
    else if (y>=50)
        cout<<"Pass"<<endl;
    else
        cout<<"Fail"<<endl;
    return 0;
    }
Last edited on
Adding on to WSiaB's code, you could include string, so the user can input names with spaces.

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
26
27
# include <iostream>
# include <string>
using namespace std;

int main()
    {
    string x;
    int y;

    cout<<"Please Write The Student's Name:";
    getline(cin,x);

    cout<< "Please Enter the Grade Number Of "<<x<<": ";
    cin>> y;

    if (y>=85)
        cout<<"Excellent"<<endl;
    else if (y>=75)
        cout<<"Very Good"<<endl;
    else if (y>=65)
        cout<<"Good"<<endl;
    else if (y>=50)
        cout<<"Pass"<<endl;
    else
        cout<<"Fail"<<endl;
    return 0;
    }
Topic archived. No new replies allowed.