-1

I'm trying to write a program, but unfortunately, despite no error messages, the terminal output is empty. Can you please help me?

#include <stdio.h>
#include <stdlib.h>

double tuitonFee(int student_id, int credit, int year, double tuiton_0, double tuiton_1);

int main()
{
    int student_id, credit, year;

    printf("Enter the student id (-1 to exit): ");
    scanf_s("%d", &student_id);

    if (student_id == -1)
    {
        exit(0);
    }

    printf("Enter the credit: ");
    scanf_s("%d", &credit);

    printf("Enter year: ");
    scanf_s("%d", &year);

    double tuiton_0 = 525 * credit;
    double tuiton_1 = 4500 + (750 * credit);

    double tuitonFee(student_id, credit, year, tuiton_0, tuiton_1);

    return 0;
}

double tuitonFee(int student_id, int credit, int year, double tuiton_0, double tuiton_1)
{
    if (credit <= 12)
    {
        if (year == 4)
        {
            printf("Student with id %d will pay tuiton %.0lf$", student_id, tuiton_0);
        }
        else
        {
            printf("Student with id %d will pay tuiton %.0lf$", student_id, tuiton_0 * 0.15);
        }
    }
    else if (credit > 12)
    {
        if (year == 4)
        {
            printf("Student with id %d will pay tuiton %lf$", student_id, tuiton_1);
        }
        else
        {
            printf("Student with id %d will pay tuiton %.0lf$", student_id, tuiton_1 * 0.15);
        }
    }
    return credit;
}

I tried to change variables, and function names and research the problem on the internet, but I didn't find the solution.

Yksisarvinen
  • 18,008
  • 2
  • 24
  • 52
eesenn0
  • 19
  • 2
  • 3
    Does this answer your question? [What is a debugger and how can it help me diagnose problems?](https://stackoverflow.com/questions/25385173/what-is-a-debugger-and-how-can-it-help-me-diagnose-problems) – mkrieger1 Dec 10 '22 at 10:30
  • What platform is this running on? Try adding `fflush(stdout);` after each call to `printf`. – David Grayson Dec 10 '22 at 10:31
  • I'm using visual studio and adding fflush(stdout); it didn't make any difference. – eesenn0 Dec 10 '22 at 10:44
  • 2
    `double tuitonFee(student_id, credit, year, tuiton_0, tuiton_1);` does not call the function. – Eric Postpischil Dec 10 '22 at 11:20

2 Answers2

2

I'm unsure what you mean here. Is it not outputting at all for you? On my system, the code gets to the point of asking my student id, credit, and year before terminating without outputting the prints in the tuitionFee function.

If it is doing the same for you, the solution is to omit the double type assignment before your call to tuitionFee(). Either way this will likely need to be done as I doubt this current state was intentional

What you are doing on this line:

double tuitonFee(student_id, credit, year, tuiton_0, tuiton_1);

is declaring a new function prototype instead of calling your function. Your function is thus not getting called at all.

In order to call your funtion, this is the line of code you should use

tuitonFee(student_id, credit, year, tuiton_0, tuiton_1);

// or, seperatly
double returnedValue = tuitonFee(student_id, credit, year, tuiton_0, tuiton_1);

If you simply see no output for the entire program, the issue is not with your codes logic however

2

In a function calling datatype is not reqired.

You also don't need to return double type, void work perfectly for static print();

getch() is used for stop the console for showing output.

#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
void tuitonFee(int student_id, int credit, int year, double tuiton_0, double tuiton_1);

int main()
{
    int student_id, credit, year;

    printf("Enter the student id (-1 to exit): ");
    scanf("%d", &student_id);

    if (student_id == -1)
    {
        exit(0);
    }

    printf("Enter the credit: ");
    scanf("%d", &credit);

    printf("Enter year: ");
    scanf("%d", &year);

    double tuiton_0 = 525 * credit;
    double tuiton_1 = 4500 + (750 * credit);

    tuitonFee(student_id, credit, year, tuiton_0, tuiton_1);

    getch();
    return 0;
}

void tuitonFee(int student_id, int credit, int year, double tuiton_0, double tuiton_1)
{
    if (credit <= 12)
    {
        if (year == 4)
        {
            printf("Student with id %d will pay tuiton %.0lf$", student_id, tuiton_0);
        }
        else
        {
            printf("Student with id %d will pay tuiton %.0lf$", student_id, tuiton_0 * 0.15);
        }
    }
    else
    {
        if (year == 4)
        {
            printf("Student with id %d will pay tuiton %lf$", student_id, tuiton_1);
        }
        else
        {
            printf("Student with id %d will pay tuiton %.0lf$", student_id, tuiton_1 * 0.15);
        }
    }
}