A community for students.

Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

anonymous

  • 4 years ago

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!

  • This Question is Closed
  1. farmdawgnation
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 3

    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?)

  2. anonymous
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    Yeah, we are using G++. And as for any previous programming, I took a QBasic class in High School, but that's about it :/

  3. farmdawgnation
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 3

    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

  4. farmdawgnation
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 3

    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. :)

  5. anonymous
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    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!

  6. farmdawgnation
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 3

    Glad I could help! :)

  7. anonymous
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    Made in Visual Studio 2010: #include "stdafx.h" #include <string> #include <iostream> 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; }

  8. farmdawgnation
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 3

    That won't work in g++. ;)

  9. anonymous
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    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
  10. farmdawgnation
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 3

    Don't use _TCHAR*. Just use char* and you'll be fine. Additionally, make the method main, instead of _tmain.

  11. anonymous
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    I've made a decent bit of progress I think, here's what I've gotten so far: #include "stdafx.h" #include <iostream> 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
  12. farmdawgnation
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 3

    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. :)

  13. anonymous
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    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?

  14. anonymous
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    So here is, I hope, the final source for my assignment: // James Hegyi Project 1.cpp : main project file. #include "stdafx.h" #include <string> #include <iostream> 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!

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

    • Attachments:

Ask your own question

Sign Up
Find more explanations on OpenStudy
Privacy Policy

Your question is ready. Sign up for free to start getting answers.

spraguer (Moderator)
5 → View Detailed Profile

is replying to Can someone tell me what button the professor is hitting...

23

  • Teamwork 19 Teammate
  • Problem Solving 19 Hero
  • You have blocked this person.
  • ✔ You're a fan Checking fan status...

Thanks for being so helpful in mathematics. If you are getting quality help, make sure you spread the word about OpenStudy.

This is the testimonial you wrote.
You haven't written a testimonial for Owlfred.