Did alot of searching but to be honest I have no idea...

This is a discussion on Did alot of searching but to be honest I have no idea... within the C Programming forums, part of the General Programming Boards category; Hey C programming forums its me again :P Still doing basics of C I get alot of whats being told ...

  1. #1
    Registered User
    Join Date
    Jan 2011
    Posts
    5

    Did alot of searching but to be honest I have no idea...

    Hey C programming forums
    its me again :P
    Still doing basics of C

    I get alot of whats being told in the book, and its helping me think for myself and after about a good 20 mins of searching I have no idea how to fix this error.

    As an exercise I have to build a program that scans values of wages, hours worked, and tax rate which than becomes a final value in the variable final_payment.

    Unfortunately I keep getting segmentation errors when everyone enters their hour wages (first variable).
    Now I get 2 warning messages when compiled so maybe that is the reason why and I can honestly tell you I don't completely get exactly about conversion specifiers and how different types integrate with each other so I am hoping you guys/girls can clear things up.

    Code:
    #include <stdio.h>
    
    int main(void)
    {
        float u_wage;
        int tax_rate;
        int u_hours;
        float final_payment;
    
        printf("Enter the amount of pay you get per hour: ");
        scanf("%f", u_wage);
        printf("Enter the amount of hours you worked: ");
        scanf("%d", u_hours);
        printf("Enter your current tax rate to be deducted from your pay: \n");
        final_payment = (u_wage * u_hours) - (tax_rate/100);
        printf("Your final payment is %f", final_payment);
    
        return 0;
    
    }
    Warnings:
    Code:
    |warning: format ‘%f’ expects type ‘float *’, but argument 2 has type ‘double’|
    warning: format ‘%d’ expects type ‘int *’, but argument 2 has type ‘int’|
    ||=== Build finished: 0 errors, 2 warnings ===|

  2. #2
    Registered User
    Join Date
    Jan 2009
    Location
    Australia
    Posts
    375
    scanf does not expect variables themselves, it expects the address of the variable.

    To supply the address of a variable, you use an ampersand (&) before the variable name.

    scanf("%s", &string );

    I'm assuming you haven't covered pointers yet, it will become more clear when you do. For now just remember to supply the address of a variable when a function expects it.

  3. #3
    Registered User
    Join Date
    Jan 2011
    Posts
    5
    wow i fail lol
    im such a dumbass :P
    this was like chapter 1 stuff and totally slipped my mind that for scanf i gotta supply that symbol ahah jeez.

    noob error XD

    Thanks for the help

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. An idea that's out of my reach of knowledge
    By Akkernight in forum Tech Board
    Replies: 12
    Last Post: 04-08-2009, 10:35 PM
  2. File Searching with _findfirst and _findnext
    By l WolfPac l in forum C Programming
    Replies: 1
    Last Post: 01-03-2003, 02:55 AM
  3. A simple idea for the boards
    By DISGUISED in forum A Brief History of Cprogramming.com
    Replies: 4
    Last Post: 08-09-2002, 01:06 PM
  4. searching linked lists
    By spentdome in forum C Programming
    Replies: 1
    Last Post: 04-21-2002, 07:46 PM
  5. Replies: 2
    Last Post: 01-02-2002, 02:05 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21