Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Expected expression before '<=' token

  • 24-01-2012 2: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,317 ✭✭✭✭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