• C

Calculations

Hey Again,
If you look at the code below you will beable to see what I am doing.
But the result I get returns a value to long. ie,
wages for week excluding overtime 421.000000 pounds.
when I want it to be like so   -  421.00 pounds.
How do i do this.

Many Thankx

#include <stdio.h>

void main()
{
int hours,ovehrs,amount;

printf(" Please enter the amount of standard hours you worked ");
scanf("%d", &hours);

printf("\n Now how many Hours overtime you worked ");
scanf("%d", &ovehrs);
{
float pounds,amount;

printf(" Enter Hourly rate ");
scanf("%f", &pounds);
amount = (float)hours*(float)pounds;
printf("Wages for week excluding Over time %f pounds");
}
}

Who is Participating?

Commented:
#include <stdio.h>

void main()
{
int hours,ovehrs,amount;

printf(" Please enter the amount of standard hours you worked ");
scanf("%d", &hours);

printf("\n Now how many Hours overtime you worked ");
scanf("%d", &ovehrs);
{
float pounds,amount;

printf(" Enter Hourly rate ");
scanf("%f", &pounds);
amount = (float)hours*(float)pounds;
printf("Wages for week excluding Over time %.2f pounds");
}
}
0

Commented:
notice .2f instead of f ... that's how you specify precision

from UNIX man pages for fprintf ( printf is essentially fprintf to stdout )
-=-=-=-=-=-==--=-=-=-=-=-=-
An optional precision that gives the minimum number of digits to appear for the d, i, o, u, x and X conversions; the number of digits to appear after the radix character for the e, E and f conversions; the maximum number of significant digits for the g and G conversions; or the maximum number of bytes to be printed from a string in s  and S  conversions. The precision takes the form of a period (.) followed either by an asterisk (*), described below, or an optional decimal digit string, where a null digit string is treated as 0. If a precision appears with any other conversion character, the behaviour is undefined.
0

Author Commented:
Thats Excellent Mate,
Thank You..
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.