samedi 24 décembre 2016

Only if statement shows though different input

#include <stdio.h>
int printMenu(int);
int studentglobal;
float getCarryMark(float);
float getFinalMark(float);
float calculateScore(float);
int printMessage(int);
float cm1,crym,final2,final1,f50,totalglobal;
int message,messageglobal,ms1;


main()
{
    printf("-----------------------------------------------------\n");
    printf("\t\tTotal Score calculator\n");
    printf("-----------------------------------------------------\n");
    int counter, x, studentcount = 1, sum = 0;


    x = printMenu(studentglobal);

    for (counter = 0; counter < x; counter++)

    {
        studentcount = studentcount + counter;
        printf("Student : %d \n", studentcount);
        crym = getCarryMark(cm1);
        while (crym >= 0 || crym <= 50)
        {

            if (crym >= 0 && crym <= 50)
            {
                printf("right range!!\n");
                f50 = getFinalMark(final1) * 0.5 ;
                printf("You final mark converted to 50 percent is %.2f\n", f50);
                printf("Total : %.2f\n", calculateScore(totalglobal));
                printf("%d\n", printMessage(ms1));
                messageglobal = printMessage(ms1);

                if (messageglobal = 1)
                {
                    printf("Excellent!!\n");
                    printf("-----------------------------------------------------\n");
                }
                else if (messageglobal = 2)
                {
                    printf("You are good at this course.\n");
                    printf("-----------------------------------------------------\n");
                }
                else if (messageglobal = 3)
                {
                    printf("Not good enough but don’t give up easily.\n");
                    printf("-----------------------------------------------------\n");
                }
                else if (messageglobal = 4)
                {
                    printf("You better repeat this course\n");
                    printf("-----------------------------------------------------\n");
                }
                break;
            }
            else
            {
                printf("INVALID RANGE!!!\n");
                crym = getCarryMark(cm1);
            }
        }
    }

}

int printMenu(int nstudent)
{
    printf("Enter no of student: ");
    scanf("%d", &nstudent);
    return(nstudent);
}

float getCarryMark(float carrymark)
{
    printf("Enter your carrymarks: ");
    scanf("%f", &carrymark);
    return(carrymark);
}

float getFinalMark(float final)
{
    printf("Enter your final mark : ");
    scanf("%f", &final);
    while (final>= 0 || final <= 100)
    {

        if (final >= 0 && final <= 100)
        {
            printf("right range!!\n");
            break;

        }
        else
        {
            printf("INVALID RANGE!!!\n");
            printf("Enter your final mark : ");
            scanf("%f", &final);
        }
    }
    return(final);
}

float calculateScore(float total)
{
    total = f50 + crym;
    return (total);
}

int printMessage(message)
{
    if (totalglobal > 80)
    {
        message = 1;
    }
    else if (totalglobal >= 60 && totalglobal <= 79)
    {
        message = 2;
    }
    else if (totalglobal >= 50 && totalglobal <= 59)
    {
        message = 3;
    }
    else if (totalglobal >= 0 && totalglobal <= 49)
    {
        message = 4;
    }
    return(message);
}


output

Total Score calculator

Enter no of student: 2 Student : 1 Enter your carrymarks: 0 right range!! Enter your final mark : 0 right range!! You final mark converted to 50 percent is 0.00 Total : 0.00 4

Excellent!!

Student : 2 Enter your carrymarks: 0 right range!! Enter your final mark : 0 right range!! You final mark converted to 50 percent is 0.00 Total : 0.00 4

Excellent!!

Press any key to continue . . .

As i enter zero for both mark suppose the program output you have to repeat this course! but instead it show excellent!.

i told to use int printMessage(message) function and i didnt learn how to return string and i used interger to activate the message.

Aucun commentaire:

Enregistrer un commentaire