Newbie Question

This is a discussion on Newbie Question within the C++ Programming forums, part of the General Programming Boards category; That shouldn't make a difference elad. robshirah, why didn't you take my advice? I'm pretty sure your formulae are wrong. ...

  1. #16
    mustang benny bennyandthejets's Avatar
    Join Date
    Jul 2002
    Posts
    1,401
    That shouldn't make a difference elad.

    robshirah, why didn't you take my advice? I'm pretty sure your formulae are wrong. These should be the calculations:

    <40 Hours:
    gross=salary*hours
    tax=gross*.75

    >40 Hours:
    gross=(salary+1)*hours
    tax=gross*.75

    Using those formulae should fix any problems you're having. Plus, using my structure will make your program more efficient.

    Code:
    cout <<"Please enter workers total hours: ";
    cin >>hours;
    cout <<"\n";
    
    
    cout <<"Please input workers salary: ";
    cin >>salary;
    cout <<"\n";
    
    if (hours <= 40)
        gross = salary*hours;
    else
        gross = (salary+1) * hours;
    
    tax = gross*.75;
    benforbes@optusnet.com.au
    Microsoft Visual Studio .NET 2003 Enterprise Architect
    Windows XP Pro

    Code Tags
    Programming FAQ
    Tutorials

  2. #17
    Registered User
    Join Date
    Sep 2003
    Posts
    7
    OK once again thanks to all who helped, I finally got it , here it is.

    Code:
    #include <iostream.h>
    
    main()
    {
    double salary;
    double hours;
    double tax;
    double gross;
    
    cout <<"Please enter workers total hours: ";
    cin >>hours;
    cout <<"\n";
    
    
    cout <<"Please input workers salary: ";
    cin >>salary;
    cout <<"\n";
    
    if (hours <= 40)
        gross = salary*hours;
    else
        gross = (salary+1) * hours;
    
    tax = gross *.75;
    
    cout <<"The workers salary after taxes is: " <<tax;
    
    return 0;
    }

  3. #18
    carry on JaWiB's Avatar
    Join Date
    Feb 2003
    Location
    Seattle, WA
    Posts
    1,972
    Although your code works you should really use the new headers and declare a return type for main (which would be int):
    Code:
    #include <iostream>
    using namespace std;
    
    int main()
    {
    ...
    "Think not but that I know these things; or think
    I know them not: not therefore am I short
    Of knowing what I ought."
    -John Milton, Paradise Regained (1671)

    "Work hard and it might happen."
    -XSquared

  4. #19
    Registered User
    Join Date
    Sep 2003
    Posts
    135
    A couple of minor points.

    C++ style is to declare variables at or just before the point of first use, rather than all at the start of a function or block.

    Also, your program source code is a form of communication between you and any readers of the code - including yourself when you come back to it later. For that reason you need to consider whether what you've written makes sense. Although this is a trivial program, if you read through it you'll find that it includes amongst it's variables one named salary and one named tax. There is an output statement that says "The workers salary after tax is " but then, it doesn't output salary at all, it outputs tax. That suggests that you haven't named your variables in the most logical way. This is even more obvious when you consider that the value held by the variable tax isn't the amount of tax, it's the net salary. The value held by salary is the hourly rate.

    Getting your program to work is one thing, but it's important also that it makes sense to someone reading it.

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Stupid Newbie question
    By TimL in forum C++ Programming
    Replies: 4
    Last Post: 07-22-2008, 04:43 AM
  2. C prog newbie question
    By Draginzuzu in forum C Programming
    Replies: 1
    Last Post: 02-03-2003, 05:45 PM
  3. a stupid question from a newbie
    By newcomer in forum C++ Programming
    Replies: 4
    Last Post: 01-11-2003, 03:38 PM
  4. confusion with integers (newbie question)
    By imortal in forum C Programming
    Replies: 7
    Last Post: 12-06-2002, 03:09 PM
  5. newbie class templates question
    By daysleeper in forum C++ Programming
    Replies: 2
    Last Post: 09-18-2001, 09:50 AM

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