Need Algorithm to C++ Code Conversion Assistance, Please!!

Discussion in 'C++' started by newtocplus432, Aug 22, 2011.

  1. newtocplus432

    newtocplus432 New Member

    Joined:
    Aug 22, 2011
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    Hello and thanks for reading my post. I need help converting the fallowing Algorithm into working C++ code, and below is what i have come up with so far, what do i need to do to make this compile?

    Algorithm:

    PayCalc

    1. CaseOf
    PayCode = "H"
    Pay = Rate * Hours
    Paycode = "P"
    Pay = Rate
    Paycode = "C"
    Pay = Commission * Sales
    Paycode = "S"
    Pay = Salary

    EndOfCase

    2. Exit

    Code:

    Code:
    #include <iostream> 
    using namespace std;
    int main()
    {
    char H, P, C, S, paycode;
    double paycode_h, paycode_p, paycode_c, paycode_s, rate, hours, pay, commission, sales, salary;
    cout << "Enter Your Paycode (H,P,C,S).";
    cin >> paycode;
    switch(paycode)
    
    {
    
    case 'H':
    cout << "Pay = Rate * Hours" << endl;
    cin << paycode_h;
    case 'P':
    cout << "Pay = Rate * NoPieces" << endl;
    cin << paycode_p;
    break;
    case 'C':
    cout << "Pay = Commission * Sales" << endl;
    cin << paycode_c;
    break;
    case 'S': 
    cout << "Pay = salary"<< endl;
    cin << paycode_s;
    break;
    default: 
    cout << "You must enter a valid Paycode" << endl;
    
    
    }
    return 0;
    }
    Thank You!
     
    Last edited by a moderator: Aug 22, 2011
  2. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,009
    Likes Received:
    203
    Trophy Points:
    63
    Occupation:
    Senior Support Engineer
    Location:
    England
    Have you tried compiling it? Did you get any errors?

    You need a break at the end of each case (unless you mean for it to run into the next one, and a good tip is that if you really mean it to do that then you should put a comment in to that effect). But it will compile and run without that.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice