so this is my final grade calculator that i turned in, and my teacher came back and said my IF/ELSE structure was Malformed, Is there something i did poorly, or wrong, what can i do to make it better. any suggestions will be taken accounted for

#include <stdio.h>


int main() {
// initialize variables needed for user inputs and calculations
	int grade1 = 0;
	int grade2 = 0;
	int grade3 = 0;
	int grade4 = 0;
	int midterm = 0;
	int attendence = 0;
	int totalPoints = 0;
	int gradepercentage = 0;
	int total = 0;
	int finalexam = 0;
	int finalExam2 = 0;
	float eightfiftytotal = 850; 
	char gradeLetters[5] = "ABCD";
	
	//display and ask user for score inputs with error correction

	printf("Please enter your scores from 0-150 \n\n");

	printf("Please enter your first score and press enter: \n");
	scanf("%d", &grade1);
	fflush(stdin);

	printf("Please enter your second score and press enter: \n");
	scanf("%d", &grade2);
	fflush(stdin);

	printf("Please enter your third score and press enter: \n");
	scanf("%d", &grade3);
	fflush(stdin);

	printf("Please enter your fourth score and press enter: \n");
	scanf("%d", &grade4);
	fflush(stdin);

	printf("Please enter your Midterm score and press enter: \n");
	scanf("%d", &midterm);
	fflush(stdin);

	printf("Please enter your Attendence score out of 100: \n\n");
	scanf("%d", &attendence);
	fflush(stdin);

// add all the inputs and display the total points then calculate the percentage

	totalPoints=grade1+grade2+grade3+grade4+midterm+attendence;
	total=totalPoints/eightfiftytotal*100;

	printf("your total points are: %d out of 850\n\n", totalPoints);

	
	
// display the grade letter and grade percentage with IF/ELSE 

	printf("GRADE-----||-----PERCENTAGE:  \n\n");
	

	if((int) total >= 90 && total <= 500) {
		printf("%c---------||-----%d Percent\n\n ", gradeLetters[0], (int) total);
	}
	else if((int) total >= 80 && total <= 89) { 
		printf("%c---------||-----%d Percent\n\n", gradeLetters[1], (int) total);
	}
		else if((int) total >= 70 && total <= 79) {
			printf("%c---------||-----%d Percent\n\n", gradeLetters[2], (int) total);
		}
			else if((int) total >= 60 && total <= 69) {
				printf("%c---------||-----%d Percent\n\n", gradeLetters[3], (int) total);
			}
				else if((int) total <= 59) {
					printf("You are failing with a %d percent \n\n", (int) total);
				}
		
	


	return 0;

}

It isn't necessary to typecast total because total was declared as an int

I would line up all the else's and reverse the order of the tests

if( total < 60)
    printf("You are failing with a %d percent \n\n", (int) total);
else if( total < 70)
    printf("%c---------||-----%d Percent\n\n", gradeLetters[3], total);
else if( total < 80)
<etc. etc.>

In the if ... else block you have used the variable total twice. I think you meant to use totalPoints in one of the places ...

Also if I am using 2 conditions separated by a logical operator in an if statement trying I write it like this

if ( (a <100) && (a >50))
{}

This makes it easy for me to spot an error in my conditions

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.