anonymous
  • anonymous
Hey, I'm very new to Computer Science type stuff, and unfortunately for a class I'm in (Intro. to C++ Programming), I don't have my textbook yet, and I'm pretty much completely clueless as to what to do for my first assignment! Here is the description of what I'm supposed to do: "Write a program that inputs a name, pay rate, and number of hours worked. The program computes the salary for the person." Any and all help would be very much appreciated!
Computer Science
  • Stacey Warren - Expert brainly.com
Hey! We 've verified this expert answer for you, click below to unlock the details :)
SOLVED
At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat.
jamiebookeater
  • jamiebookeater
I got my questions answered at brainly.com in under 10 minutes. Go to brainly.com now for free help!
farmdawgnation
  • farmdawgnation
So, first off a few questions: 1. Have you gotten a compiler set up on your computer? (Most classes like this will use g++ or gcc) 2. Have you ever written any type of program before? (i.e. a Java program?)
anonymous
  • anonymous
Yeah, we are using G++. And as for any previous programming, I took a QBasic class in High School, but that's about it :/
farmdawgnation
  • farmdawgnation
Oy, right, well, I don't want to do the whole assignment for you - it'll probably only be 10-20 lines total - but I can give you some links that'll help you out. First, you need to understand how C programs are set up with the main method and basic input/output. This article should get you started in the right direction: http://www.cprogramming.com/tutorial/lesson1.html

Looking for something else?

Not the answer you are looking for? Search for more explanations.

More answers

farmdawgnation
  • farmdawgnation
Once you get to a point where you start having "why doesn't this work" questions, come here and post them and we'll be able to help you out. :)
anonymous
  • anonymous
Thanks so much, that's exactly what I was looking for! I was doing a bunch of random google searches trying to find some good websites (the curse of buying a textbook online is waiting for the shipping!), but nothing came up, thanks so much!
farmdawgnation
  • farmdawgnation
Glad I could help! :)
anonymous
  • anonymous
Made in Visual Studio 2010: #include "stdafx.h" #include #include using namespace std; int _tmain(int argc, _TCHAR* argv[]) { string name; int salaryRate, hoursWorked; cout << "Name please?"; getline(cin, name); cout << "Salary rate?"; cin >> salaryRate; cout << "Hours worked?"; cin >> hoursWorked; cout << name << "'s salary is " << salaryRate * hoursWorked << "." << std::endl; system("pause"); return 0; }
farmdawgnation
  • farmdawgnation
That won't work in g++. ;)
anonymous
  • anonymous
So I may have mis-spoken earlier when I said it was g++ we are using, the actual program I load up is Visual Studio 2010. When I use that program though (after adding in the name/wage etc.), I get an error when I debug (which from what I understand is basically checking to see if the written program works?), it keeps giving me an error with "_TCHAR", here is a screencap of what it all looks like (sorry it this is big)
1 Attachment
farmdawgnation
  • farmdawgnation
Don't use _TCHAR*. Just use char* and you'll be fine. Additionally, make the method main, instead of _tmain.
anonymous
  • anonymous
I've made a decent bit of progress I think, here's what I've gotten so far: #include "stdafx.h" #include using namespace std; int main() { cout << "Name: James\n"; cout << "Pay Rate: $8.50\n"; cout << "Hours Worked: 30\n"; cout << "James's salary is $" << 7.5 * 30 << "."; system("pause"); } Now, when I debug that, it works fine, and the final product looks just like it's supposed to, but I'm pretty sure I'm not getting it the way I'm supposed to. Here's an attachment of a sample input/output. What has me confused is the input where it's talking about the Prompts/user inputs, I'm not sure what that means, but I feel pretty sure I'm not following it :(
1 Attachment
farmdawgnation
  • farmdawgnation
Right, so what you need to do is actually take the "Name", "Pay Rate", and "Hours Worked" as values from the standard input. So when your program is working properly, the actual exchange should look something like: Input Name: James Input Pay Rate: 8.50 Input Hours Worked: 30 Total Pay: $255.00 After each "Input..." prompt, you should be entering those values while the program is running. I recommend looking at cin. :)
anonymous
  • anonymous
So, when I run debug, the first thing that would come up would be "Name:", and then I enter the name, and then when I get to the next line, It would show up as "Pay Rate:" and I would enter it in?
anonymous
  • anonymous
So here is, I hope, the final source for my assignment: // James Hegyi Project 1.cpp : main project file. #include "stdafx.h" #include #include using namespace std; int main () { string name; float payRate, hoursWorked; cout << "Name:"; getline(cin, name); cout << "Pay Rate: $"; cin >> payRate; cout << "Hours Worked:"; cin >> hoursWorked; cout << name << "'s salary is $" << payRate * hoursWorked << " per week." << std::endl; system("pause"); return 0; } It works exactly how I think it's supposed to! The last issue I had was setting it up to use decimals for the payRate, but I figured out I just needed to use float instead of int, and now it's working great! Thanks so much for all the help! I know I didn't write most of the frame of this specific code, but I definitely feel very comfortable with most of the concepts within this specific assignment now!

Looking for something else?

Not the answer you are looking for? Search for more explanations.