Thread: Newbie needs help..

  1. #1
    Registered User
    Join Date
    Jul 2007
    Posts
    1

    Newbie needs help..

    i am taking C++ in school and i got my first assignment i bought the required text but it will receive at next week but i want to get this assignment over with here the question if anybody can help me out i would appreciate it..thanks in advance here the question

    "WRITE A COMPLETE C++ PROGRAM,USING CIN AND COUT << STATEMENTSS,FOR THE FOLLOWING:

    A SALES COMPANY NEEDS A PROGRAM THAT ALLOWS THEIR STORE CLERKS TO ENTER NUMBER OF BOXES IN STOCK AT THE BEGINNING OF THE CURRENT MONTH,THE NUMBER OF BOXES PURCHASED DURING THE CURRENT MONTH AND THE NUMBER OF BOXES SOLD DURING THE CURRENT MONTH.THE PROGRAM SHOULD CALCULATE AND DISPLAY THE NUMBER OF BOXES IN STOCK AT THE END OF THE CURRENT MONTH.
    ANY HELP WOULD BE APPRECIATED!!

  2. #2
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Ireland
    Posts
    8,446
    It's that time of year again.

    Check this website tutorials (search google for "cprogramming cin cout" or "c++ cin cout tutorial"). And pay attention to class next time.
    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    Certainly lives up to his nickname, what with all the yelling.
    http://www.catb.org/~esr/faqs/smart-...html#writewell

    > i am taking C++ in school and i got my first assignment
    Do you have a backup plan?
    You know, the one where you drop the course next week and enrol at burger world university.

    Because if your first reaction to getting your first assignment is to post it on a message board without any effort, then either you didn't show up for class, or you're simply not cut out to be a programmer. In either case, you're wasting everybody's time.

    Betchadidntreadthiseither
    http://cboard.cprogramming.com/annou...t.php?f=3&a=39
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  4. #4
    Hardware Engineer
    Join Date
    Sep 2001
    Posts
    1,398
    Welcome to the forum, xpress urself.

    Since you are new, and you don't have your book yet, I won't be so hard on you. Although it's "illegal" for us to do your homework for you, I think it's OK to to ask a question like "How do I get started", or "What am I doing wrong here?"

    Even if it's not homework, nobody here is going to write your program for you! We are here to help you write your program. Even if your question doesn't involve homework, we are more likely to answer with "hints" than with a direct answer. Programmers enjoy solving puzzles, and we want you to solve your puzzle yourself too!

    First, take a look at the tutorial here at cprograming.com. The first lesson might be enough to get you started, or even enough to complete the assignment. Here's another tutorial.

    The online tutorials are very brief and condensed. This can be deceiving. You can probably read-through the entire tutorial in about an hour, but it's going to take the full semester to really learn it all. Your textbook will essentially cover the same material, but with several-hundred pages of detail and explanation. ...You could read through your math textbook in one day too, but you can't learn it all in a day!

    Think about the steps your program has to do, and work on one thing at a time...
    - Create some variables to hold the numbers
    - Ask the user for input
    - Add & subtract some numbers
    - display the result.



    I've got to sign-off now. I'll write a few more words later...
    -------------------------------------------------------
    ...I'm back.



    The first thing to do, is to make sure your compiler is set-up and working properly. If you haven't done so already, try compiling (and running) "Hello World" (the first program in the tutorial). Whenever you try-out a new compiler, you should try compiling "Hello World".


    YOUR PROGRAM - Take it step-by-step. Write one or two lines of code, then test-compile and test-run. When that works, add one or two more lines. Most beginners try to write the whole program before trying it out. Then they get frustrated when the compiler reports 25 errors in a 10-line program! ...I'm not kidding. Compilers can get confused... Once they hit the 1st or 2nd error, they can sometimes start seeing everything else as an error.

    You should always follow this technique. As you gain experience and your programs become bigger, you will write more than one or two lines at a time, but you should almost never write the whole program before compiling & testing!


    1. Start out with the Hello World program, and change the cout text to something like "Inventory Program".

    2. Create the first variable, something like BoxesAtBeginning.
    Set that variable to a temporary "test" value... Maybe 10 or something.

    3. Write a cout statement that displays "Number of boxes at beginning of month", and that also displays the value of the variable. You will remove this statement (line of code) later. It's just there now for testing & debugging.

    ---- TEST COMPILE and TEST RUN ----- (debug as required)
    The variable should display as you've programmed it.

    4. Do the same with the remaining variables. Create them, assign temporary values to them, and display their values.

    ---- TEST COMPILE and TEST RUN ----- (debug as required)
    All of the variables should display as you've programmed them.

    5. Write the line of code that does the addition & subtraction and assigns the result to the end-of-month count*.
    Delete the line that assigned a temporary test value to the end-count, since it's now getting calculated by the program.


    6. Move the line of code that displays the end-of-month count to the end, after the above calculation.

    ---- TEST COMPILE and TEST RUN ----- (debug as required)
    The correct end-count should display.

    7. Go to the top of the program and add a cout statement that asks the user to enter the beginning count.

    8. Write a cin line that gets the beginning count number from the user and assigns it to the variable.
    Delete the line that assigns a temporary-test value for the beginning-count.

    ---- TEST COMPILE and TEST RUN ----- (debug as required)
    The correct end-count should display, based on your whatever start-count you enter each time you run the program.

    9. Add cout statements asking for the other variables, and the associated cin statements to get the actual values from the user (when you run the program).
    Delete the lines that assign temporary-test values.

    ---- TEST COMPILE and TEST RUN ----- (debug as required)
    At this point, your program is essentially DONE!

    10. Clean-up by removing the temporary cout statements that repeat what the user enters.

    ---- TEST COMPILE and TEST RUN ----- (debug as required)
    DONE!!!!


    I might have missed something there... But try to follow the general concept. Write - test - write - test write - test.

    -------------------------------------------------------------------------------------------
    If this is a university course, it will cover lots of material very quickly. It could be a disaster if you get behind in the beginning because you don't have the book. And, be prepaired to spend lots of time doing homework. You can (and will) easily spend several hours looking for one simple little-tiny bug!

    Try to get into a study group. It's This stuff is much easier to learn when you work together. Most university professors will encourage group study. Programming is HARD!. It's especially hard when it's your first progamming language.
    -------------------------------------------------------------------------------------------



    * NOTE - When you write an expression (a line of code that results in a value), the result or "unknown" goes on the LEFT SIDE.

    X = 1 + 2; // Correct
    1 + 2 = X; // Wrong! Compiler will report an "l-value error" (left-value error).
    BoxesAtEnd = BoxesAtBeginning + BoxesPurchased - BoxesSold; // Correct. The result/answer is on the LEFT.
    Last edited by DougDbug; 07-26-2007 at 11:21 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. getting to grips with allegro and ms vc++ (newbie)
    By jimjamjahaa in forum C++ Programming
    Replies: 4
    Last Post: 11-18-2005, 07:49 PM
  2. Newbie in problem with looping
    By nrain in forum C Programming
    Replies: 6
    Last Post: 11-05-2005, 12:53 PM
  3. Newbie Programmer
    By Extropian in forum C++ Programming
    Replies: 3
    Last Post: 05-18-2004, 01:17 PM
  4. C++ newbie / linux not so newbie question
    By goldmonkey in forum C++ Programming
    Replies: 7
    Last Post: 12-13-2003, 12:27 PM
  5. Newbie Game Develpoers Unite!
    By Telenosis in forum Game Programming
    Replies: 10
    Last Post: 06-22-2002, 02:02 PM