Thread: A Little Help

  1. #1
    Registered User
    Join Date
    May 2010
    Posts
    7

    A Little Help

    Okay So I started writing this for extra credit, but damn i need decimal , and when i try to insert something that isnt a whole number i have a problem so if its not int, is it float? and where in the code does it go? Then i need a loop to repeat it 5 times which i am totally lost...... yes i am noob:*(




    Write a program that reads in the name, hourly rate and number of hours worked for 5 people. Print the name of each person, the number of hours worked, their weekly pay based on the number of hours they worked and how much they owe in taxes. Assume that taxes take 20% of the paycheck. Don’t forget to take the taxes out of the pay check. If they work more than 40 hours they get overtime. The hourly rate is then 1.5 times normal for all hours past 40.

    Example (Sample input & output for one person)
    Enter name: Glenn
    Enter hourly rate: 4.00
    Enter hours worked: 75

    Pay to: Glenn
    Hourly rate: 4.00
    Hours worked: 75.0
    Amount paid: $370.00
    Taxes paid: $74.00


    My Code:
    #include<stdio.h>

    int main()
    {

    int hoursWorked;

    int hourlyRate;

    int sum;

    printf("Glenn\n");

    printf("Hours Worked\n");

    scanf("%d", &hoursWorked);

    printf("Hourly Wage\n");

    scanf("%d", &hourlyRate);

    sum = hoursWorked * hourlyRate;

    printf("The Total Is %d", sum);

    getch();

    return 0;
    }

  2. #2
    Registered User
    Join Date
    Oct 2008
    Posts
    1,262
    First of all, use code tags.

    Second of all, this is yet another "please make my homework" question, as your little challenge is. True, you ask specific questions, but that's basically everything in the entire program. Well. Yeah, use arrays. Use a for loop. Or actually, don't use arrays. Output everything as soon as the information is entered. Makes it easier...

    Don't use floating point numbers for this. Use integers. And don't store "dollars", but rather "cents".

    That's all I'll help you with until you ask specific questions.

  3. #3
    Registered User
    Join Date
    May 2010
    Posts
    7
    but i need like in hourly rate what its he earns like 12.5 when i try to type that i get like a negative long ass number, using int, how can i fix that?

  4. #4
    Registered User claudiu's Avatar
    Join Date
    Feb 2010
    Location
    London, United Kingdom
    Posts
    2,094
    You said it yourself, don't use int. Or, the best way would be to read it as a character string and convert that into a number. If you can't do it, the input is invalid.
    1. Get rid of gets(). Never ever ever use it again. Replace it with fgets() and use that instead.
    2. Get rid of void main and replace it with int main(void) and return 0 at the end of the function.
    3. Get rid of conio.h and other antiquated DOS crap headers.
    4. Don't cast the return value of malloc, even if you always always always make sure that stdlib.h is included.

  5. #5
    Registered User
    Join Date
    Oct 2008
    Posts
    1,262
    Quote Originally Posted by thedeadone100 View Post
    but i need like in hourly rate what its he earns like 12.5 when i try to type that i get like a negative long ass number, using int, how can i fix that?
    Now there's a good question. Phrase it better, with code, and post a new topic with that question. I bet it will get answer fairly soon (assuming the question is written properly). Read how to ask smart questions first.

    I think you're getting there...

  6. #6
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,318
    EVOEx , Don't suggest a new thread already, that's totally unnecessary. He's barely started this one.

    You can use doubles for this if you want. You don't need something better than that just for this assignment.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

  7. #7
    Registered User
    Join Date
    Oct 2008
    Posts
    1,262
    Quote Originally Posted by iMalc View Post
    EVOEx , Don't suggest a new thread already, that's totally unnecessary. He's barely started this one.

    You can use doubles for this if you want. You don't need something better than that just for this assignment.
    He barely used this one, yes. He screwed it up already by asking bad questions now. The following questions will be related to the original post, though the questions will be matters on itself rather than things to ask like this in one post. Personally, I prefer people to use multiple threads than continue a completely different threat to ask different questions only because it's the same assignment...

    Anyways, that said, looking at the problem again, I noticed the input are floating point numbers, so you will have to use them. Whether you do or don't convert them to integers after is your choice. While not necessary in this case, as iMalc stated, I do consider it bad practice to use floating point numbers for things that are integers, albeit in a slightly different representation.

    So doubles or integers for calculation is your choice. And I guess, starting a new post or continuing in this one is, too...

Popular pages Recent additions subscribe to a feed