Erdowi Erdowi - 1 month ago 4
C Question

What is wrong with my C code? Any pointers?

So basically, my C code output is suppose to look like so.
enter image description here

However I believe my IF statements are incorrect, can someone give it a look and give me some pointers?

#include <stdio.h>

int main()
{
int a, total = 0; // Defining integers
int n;
int tax;
int e;

float subtotal;

printf("Enter the number of days the car was rented: "); // Asking for input
scanf("%d", &n); // Establishing number of cars

printf("Enter the number of miles the car was driven: "); // Mile input
scanf("%d", &a); // Establishing miles driven

if (n > 200) {
e = .40;
}
else { e = .35;
}

subtotal = n * 15 + a * e;

printf("\nSubtotal: ", subtotal);

}

Answer

you lost something hereļ¼š

#include <stdio.h>

int main()
{
    int a, n;
    float tax, e, total = 0; // Defining integers

    float subtotal;

    printf("Enter the number of days the car was rented: "); // Asking for input
    scanf("%d", &n); // Establishing number of cars

    printf("Enter the number of miles the car was driven: "); // Mile input
    scanf("%d", &a); // Establishing miles driven

    if (n > 200) {
        e = .40;
    }
    else { e = .35;
    }

    subtotal = n * 15 + a * e;

    printf("\nSubtotal: %f", subtotal);

}
gcc filename
./a.out

and here is the result:

Enter the number of days the car was rented: 7
Enter the number of miles the car was driven: 7

Subtotal: 107.449997