-1
#include <iostream>
Using namespace std;

int main ();
{ 
cout << "What is the mean amount you work/week?" << endl;

if (input <= 40)
cout << "Your salary is $8.00/hour";
cin >> a1;
if (a1 <= 0)
cout << "";
cin >> a2;
if (a2 >= 40)
cout << a3
cin >> a3;

cout << "" << endl;
else
cout << " Better luck next time.- the correct answer is " << add << endl;

return 0;

I'm trying to write a C++ program to compute and display a person’s salary as determined by the following expressions:

If hours worked <= 40, the person receives $8/hour otherwise, Person receives the first 40hrs @ $8/hr remaining hrs at 1.5x basic rate.
Program should request: 1) hours worked (input) 2) display the salary earned (output).
Use a constant variable for basic rate so the program can be updated easily when hourly rates change.
Give appropriately input/output. Test program several x with hrs below, =, and above 40.

Any direction will be greatly appreciated!

Justin Chiang
  • 53
  • 2
  • 7
  • no not homework. I don't know what operators to use. I am writing this for a small business use. I'm stuck right where I am. I tried using if else and it's getting beyond my realm of understanding. – Justin Chiang Sep 28 '12 at 03:18
  • First of all, use brackets on your if-else statements, otherwise only the line directly under the statement will execute. You are using `cin` to output data on your first line in `main()` which is incorrect, it is supposed to GET data, not output it. And you dont know what operators to use? This all seems to come down to math, if you dont know which operator out of `-+/*` to use, perhaps you should brush up on your math. it seems like EVERYthing is wrong with this program. Try compiling and running it, what happens? What does your program do at its current state? – Brandon Miller Sep 28 '12 at 03:23
  • Also you have a semicolon on `int main();`, which is bad, you would have an error telling you this is wrong if you had even tried the code you have given us. Also `Using` should be `using`, and your `int main()` is missing a `}` on the very last line. – Brandon Miller Sep 28 '12 at 03:25
  • Also, none of your variables `a1`, `a2`, `a3`, are even defined. I suggest you learn C++ before trying to write a program. See: http://www.cplusplus.com/doc/tutorial/ – Brandon Miller Sep 28 '12 at 03:29
  • mr. miller thank you for your guidance. I am just needing a little guidance. I am new to c++ and more used to python unfortunately. not a comfortable transition. I can use any other charity (in the form of advice) anyone can give :) – Justin Chiang Sep 28 '12 at 03:30
  • Well, for starters you should check out that link I just posted. It covers all of the many concepts you are missing. No answer anybody can post will help you in the long run. Even if someone wrote the entire program for you, if you tried to change anything you would most likely get an error and have to come back for more help. I suggest reading that tutorial from start to end. – Brandon Miller Sep 28 '12 at 03:33

1 Answers1

1

Get some good books on C++, Check out The Definitive C++ Book Guide and List

As per your code. This is what it should be

#include <iostream>

int main () {
    int hours = 0;
    int rate = 8;

    std::cout << "Enter number of working hours?";
    std::cin >> hours;

    int pay = hours * rate;

    if (40 < hours) {
        pay += (hours - 40) * (rate / 2);
    }

    std::cout << "Total Pay" << pay << std::endl;
    return 0;
}
Community
  • 1
  • 1
Apeirogon Prime
  • 1,218
  • 13
  • 25