Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Calculations

Posted on 2001-06-17
3
Medium Priority
?
214 Views
Last Modified: 2010-04-15
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");
}      
}    

0
Comment
Question by:pnorris98
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 5

Accepted Solution

by:
djbusychild earned 800 total points
ID: 6200465
#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
 
LVL 5

Expert Comment

by:djbusychild
ID: 6200470
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 Comment

by:pnorris98
ID: 6203325
Thats Excellent Mate,
Thank You..
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
The goal of this video is to provide viewers with basic examples to understand how to use strings and some functions related to them in the C programming language.
The goal of this video is to provide viewers with basic examples to understand opening and reading files in the C programming language.

670 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question