Thread: My beginner C++ programming test.

  1. #1
    Registered User
    Join Date
    Sep 2012
    Posts
    2

    My beginner C++ programming test.

    So I recently started to try and learn the C++ programming language. I've been reading through a book about it and it has been going great except for one problem. They have no tests or anything at the end of the chapters so you really have no idea if what they just told you actually stuck in your brain or just went in and then out again. So I decided to try and create a basic program with the knowledge that I have already and was hoping that everyone here could let me know how I did and give some comments so I can see if I'm actually learning or not.

    What I have learned so far is variables, functions, (kind of touched on headers and other source files), basically all the basic stuff. I'm about halfway through the chapter on pointers at the time of writing this code. So hopefully that gives you a idea how much I know so far.


    But anyways I decided to write a program that can calculate your bi-monthly paycheck after taxes in Minnesota. The user enters his hourly wage and it returns how much he will make every 2 weeks. Was going to have the user be able to type how many hours a week he works also but I was not able to figure out how to do that yet. But enough of my yapping here is the code I created in Codeblocks.


    Code:
    #include <iostream>
    
    
    // This is my first program I have every written. Im currently trying to teach myself C++ and decided
    // to try and write a program to figure anyones pay in minnesota after taxes. I'm still very new
    // at this and have alot to learn. If you have any pointers on how to clean up the code let me know.
    
    
    using namespace std;
    
    
    // Below is my function to do the math for minnesota taxes and find the bi monthly pay.
    
    
    void Mymonthly(double *myparam)
    {
        double MySocial;
        double MyMedicare;
        double taxnumber;
        (*myparam) *= 40.0;
        (*myparam) *= 2.0;
    
    
        if ((*myparam) <= 11)
        {
            taxnumber = (*myparam) * .0535;
        }
        if ((*myparam) >= 38)
        {
            taxnumber = (*myparam) * .0785;
        }
        if ((*myparam) >= 12)
        {
            taxnumber = (*myparam) * .0705;
        }
    
    
        MyMedicare = (*myparam) * .0145;
        MySocial = (*myparam) * .0420;
    
    
        (*myparam) -= taxnumber;
        (*myparam) -= MyMedicare;
        (*myparam) -= MySocial;
    
    
        cout << "Your bi-monthly paycheck after minnesota taxes will be: " << (*myparam) << endl;
    
    
    }
    
    
    
    
    int main()
    {
        double myWage;
        cout << "Hello this program lets you find out how much you will make from your paycheck." <<
        "Please enter your hourly wage now. " << endl;
        cin >> myWage;
        Mymonthly(&myWage);
        cout << Mymonthly << endl;
    
    
        return 0;
    }
    
    
    // Thanks for looking remember that im still learning and try not to be to critical since ive only
    // just got to the part in the book that teaches my about pointers and stuff ;p.   ~ Zereo
    Thanks in advance for taking the time to look at this and give me some comments on how I did and how I could make it better. I am still very much a beginner at this and would value your feedback even it means that my code really sucks
    .

    Oh and I noticed that every time I run the program it returns a 1 right under the bi-monthly pay line. I'm not sure what is causing this but i think it has something to do with my function being wrong somewhere.

  2. #2
    - - - - - - - - oogabooga's Avatar
    Join Date
    Jan 2008
    Posts
    2,808
    Your code is well-written overall. A little more vertical spacing than I prefer.

    Maybe you were just playing with pointers, but you don't need to pass myWage as a pointer.

    You don't need to put (*myparam) in parentheses.

    The way you've written your if statements, if *myparam was, e.g., 40, it would trigger the >= 38 test and also the >= 12 test. Is that what you want? Remember that you can use "else if" to make sure only one gets executed.
    The cost of software maintenance increases with the square of the programmer's creativity. - Robert D. Bliss

  3. #3
    Registered User
    Join Date
    Sep 2012
    Posts
    2
    Quote Originally Posted by oogabooga View Post
    Your code is well-written overall. A little more vertical spacing than I prefer.

    Maybe you were just playing with pointers, but you don't need to pass myWage as a pointer.

    You don't need to put (*myparam) in parentheses.

    The way you've written your if statements, if *myparam was, e.g., 40, it would trigger the >= 38 test and also the >= 12 test. Is that what you want? Remember that you can use "else if" to make sure only one gets executed.
    Thanks for the reply. And now that I look at it your right it would trigger both of them. For some reason I thought that it would go down the line for the if statements, like if it chose the first one it would skip the rest or if it chose the second one it would not bother with the last one. Basically the IF statements are the 3 different tax brackets in my state. It gave me trouble trying to figure out how to add 3 IF's since I have only worked with 2 so far. Ill have to read up again on the else if. And ya was just readying up on pointers so decided to use them. Thanks again for the feedback.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 7
    Last Post: 02-15-2011, 02:50 PM
  2. Replies: 4
    Last Post: 03-21-2006, 10:21 PM
  3. Taking a Programming Test and need help with something.
    By 1BadRbt in forum C++ Programming
    Replies: 2
    Last Post: 03-21-2006, 06:19 AM
  4. Windows programming for beginner (Absolute beginner)
    By WDT in forum Windows Programming
    Replies: 4
    Last Post: 01-06-2004, 11:21 AM
  5. Replies: 1
    Last Post: 08-28-2001, 10:35 AM