Advertisement

What is wrong with my codes? How to use %lf? need helppp.......

Started by January 25, 2018 01:25 PM
2 comments, last by Jorex Merlin 6 years, 10 months ago

My teacher says its easy but I still can't find a solution for this, when i use %if i could get the answer but there is an f at the end of the answer so i tried using %lf again but it even gets worse and the answer becomes 0.00000 . I really couldn't find for a solution for this yet and it's been 3 days. My teacher said that we should make some research about this but i really can't find the answer even in google and youtube. This is my first time engaging in Programming so it really gave me a headache. I hope that i could get help in here. Thanks.

The output that my teacher wants us to do is just like this sample:

Enter Employee Type:r

Enter # of Hours:40

The Salary of the Regular Employee is 13280

 

...............................................................................................................

Here is the given,,

Employee type                              Salary

Regular Employee                         332/hrs

Part-time Employee                      283/hrs

Commision Employee                   8000+%Commission Employee

 

 

 

 

... here is the file that i made...  midterm practical.c

 

#include<stdio.h>
#include<conio.h>

void main()
{
    int Salary=0;
    int Hours;

    char type;
    printf("Enter Employee Type:");
    scanf("%c",&type);
    if(type=='r'||type=='R')
    {
        printf("Enter # of Hours:");
        scanf("%d",&Hours);
        Salary=332*Hours;
        printf("The Salary of the Regular Employee is %lf",Salary);
    }

    else if(type=='p'||type=='P')
    {
        printf("Enter # of Hours:");
        scanf("%d",&Hours);
        Salary=283*Hours;
        printf("The Salary of the Part-time Employee is %lf",Salary);
    }

    else if(type=='c'||type=='C')
    {
        printf("Enter # of Hours:");
        scanf("%d",&Hours);
        Salary=325*Hours;
        printf("The Salary of the Commission Employee is %lf",Salary);
    }

    else
        {
            printf("The Input is Invalid");
        }

    getch();
}
 

a1.png

a2.png

MerlinJ

https://alvinalexander.com/programming/printf-format-cheat-sheet < first result in google ;-)

Also i'd recommend you to use tolower() on type so you wouldn't need to check both 'T' and 't'. 

Advertisement

Thanks for the information and advice sir ... I'll try to do it again ...

MerlinJ

This topic is closed to new replies.

Advertisement