Question

I don't understand why the if and if else loops don't work. I also don't understand why I can't get value grade form the program (not IRL grade) past B. The logic just does not flow down. All this program is meant to do is take three input grades int (0 -100) and give a grade based on the "> or <" that are set. Yet they don't work for me. What can I do to get the if else to work? Thanks.

#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdbool.h>

// Functions 
void readScores(int* test1, int* test2, int* test3);
int determineAverage(int test1, int test2, int test3);
void print(int test3, int average, int test2_test3Av);
int avgtest2test3(int test2, int test3);


int main(void)
{
    int test1;
    int test2;
    int test3;
    int average;
    int test2_test3Av;

    readScores(&test1, &test2, &test3);  // takes input
    average = determineAverage(test1, test2, test3); // finds average
    test2_test3Av = avgtest2test3(test2, test3); // gets average of test one and two
    print(test3, average, test2_test3Av); // Prints grade resluts
    return 0;
}

void readScores(int *test1, int *test2, int *test3)
{
    // Promts
    printf("\nHello, this program will determine");
    printf("\nthe grades of an average test scores");
    printf("\nto see if you passed or not this year.");
    printf("\nPlease enter in the three test...");
    printf("\nNote: only enter scores that are (0-100)\n");

    printf("Enter in test 1\n");
    scanf(" %d", test1);
    printf("Enter in test 2\n");
    scanf(" %d", test2);
    printf("Enter in test 3\n");
    scanf(" %d", test3);
    return;
}
int determineAverage(int test1, int test2, int test3)
{
    // Local declrations
    int average;

    // Math
    average = (test1 + test2 + test3) / 3;
    return average;
}
void print(int test3, int average, int test2_test3Av)
{
    if (average >= 90)
    {
        printf("Great job you have an A %d int the class\n", average);
    }
    else if (average >= 70 && average <= 90, test3)
    {
        if (test3 >= 90)
        {
            printf("Good job you got a A %d\n", average);
        }
        else if
        {
            printf("Easy Beezy you got a B %d for the class\n", average);
        }
    }
    else if (average >= 50 && average <= 70)
    {

        if (test2_test3Av >= 70)
        {
            printf("You passed congrats you have a C %d for the class\n", average);
        }
        else if
        {
            printf("You have a D for the class %d\n", average);
        }
    }
    else if (average <= 50)
    {
        printf("Yeah you might want to take this class again you have a F %d\n", average);
    }
    return;
}

int avgtest2test3(int test2, int test3)
{
    int holder;
    holder = ((test2 + test3) / 2);
    return holder;
}

No correct solution

OTHER TIPS

Your program doesn't compile because your else statement is wrong:

 if (test3 >= 90)
 {
   printf("Good job you got a A %d\n", average);
 }
 else if // << here is the problem
 {
   printf("Easy Beezy you got a B %d for the class\n", average);
 }

Just drop the if after else:

 if (test3 >= 90)
 {
   printf("Good job you got a A %d\n", average);
 }
 else
 {
   printf("Easy Beezy you got a B %d for the class\n", average);
 }

make your problem statement clear. your program is not running cause you dint use if-else-if properly. if you use else-if then there should be a condition to check. if there is no condition then you can use if-else. i.e. your program will run if you change

if (test3 >= 90)
        {
            printf("Good job you got a A %d\n", average);
        }
        else if
        {
            printf("Easy Beezy you got a B %d for the class\n", average);
        }
    }
    else if (average >= 50 && average <= 70)
    {

        if (test2_test3Av >= 70)
        {
            printf("You passed congrats you have a C %d for the class\n", average);
        }
        else if
        {
            printf("You have a D for the class %d\n", average);
        }

this code part to

if (test3 >= 90)
        {
            printf("Good job you got a A %d\n", average);
        }
        else
        {
            printf("Easy Beezy you got a B %d for the class\n", average);
        }
    }
    else if (average >= 50 && average <= 70)
    {

        if (test2_test3Av >= 70)
        {
            printf("You passed congrats you have a C %d for the class\n", average);
        }
        else
        {
            printf("You have a D for the class %d\n", average);
        }
}

but logic you need to check. error in coding is this

else if (average >= 50 && average <= 70)
{

}

if (test3 >= 90)
 {
   printf("Good job you got a A %d\n", average);
 }
 else
 {
   printf("Easy Beezy you got a B %d for the class\n", average);
 }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top