Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

Expected expression before '<=' token

  • 24-01-2012 03:38PM
    #1
    Registered Users, Registered Users 2 Posts: 620 ✭✭✭


    Hey guys I working on a grading program for college. I'm pretty sure that I have it 90% done but i am getting a recurring error in each else if statement!I am hoping someone can point me in the right direction, thank you.
    #include <stdio.h>
    
    int main ()
    {
    	int grade=0;
    	int i=0;
    
    	printf("Please enter grade: ");
    	scanf("%d",&grade);
    
    	if (grade>100){
    		printf("Invaild percentage");
    		}
    	else if(grade>=90 && <=100){
    		i=1;}
    	else if(grade>=80 && <=89){
    		i=2;}
    	else if(grade>=70 && <=79){
    		i=3;}
    	else if(grade>=60 && <=69){
    		i=4;}
    	else if(grade>=50 && <=59){
    		i=5;}
    	else if(grade<=49){
    		i=6;}
    	
    	switch(i){
    
    	case 1: printf("Grade Awarded: A");
    		break;
    	case 2: printf("Grade Awarded:B");
    		break;
    	case 3: printf("Grade Awarded:C");
    		break;
    	case 4: printf("Grade Awarded:D");
    		break;
    	case 5: printf("Grade Awarded:E");
    		break;
    	case 6: printf("Grade Awarded:F");
    		break;
    		
    	default: printf("Invalid Percentage");
    			}
    return 0;
    }
    


Comments

  • Registered Users, Registered Users 2 Posts: 68,173 ✭✭✭✭seamus


    Although it seems logical when you read it in your head, you can't say

    grade>=90 && <=100

    You have to say

    grade>=90 && grade<=100

    Each statement on each side of the "&&" must be a complete boolean evaluation.


  • Registered Users, Registered Users 2 Posts: 620 ✭✭✭Laika1986


    seamus wrote: »
    Although it seems logical when you read it in your head, you can't say

    grade>=90 && <=100

    You have to say

    grade>=90 && grade<=100

    Each statement on each side of the "&&" must be a complete boolean evaluation.

    Ah god that's such a simple mistake!Getting back into it after christmas forgotten a few things!Thanks very much!


  • Closed Accounts Posts: 2,616 ✭✭✭8k2q1gfcz9s5d4


    is there a need for the switch? :)

    #include <stdio.h>
    
    int main ()
    {
    	int grade=0;
    	int i=0;
    
    	printf("Please enter grade: ");
    	scanf("%d",&grade);
    
    	if (grade>100){
    		printf("Invaild percentage");
    		}
    	else if(grade>=90 && grade<=100){
    		printf("Grade Awarded: A");}
    	else if(grade>=80 && grade<=89){
    		printf("Grade Awarded:B");}
    	else if(grade>=70 && grade<=79){
    		printf("Grade Awarded:C");}
    	else if(grade>=60 && grade<=69){
    		printf("Grade Awarded:D");}
    	else if(grade>=50 && grade<=59){
    		printf("Grade Awarded:E");}
    	else if(grade<=49){
    		printf("Grade Awarded:F");}
    	
    return 0;
    }
    
    


Advertisement