Thread: Help with HW Problems!!!

  1. #1
    Registered User
    Join Date
    Feb 2011
    Posts
    6

    Help with HW Problems!!!

    I am currently in a C++ Programming class and It's extremely hard for me.
    ok the, question is:

    12) Marcy's Department store is having a BoGoHo (Buy One, Get One Half Off) sale. The store manager wants a program that allows the salesclerk to enter the prices of two items. The program should both calculate and display the total amount the customer owes. The half off should always be taken on the item having the lowest price. For example, if the items cost $24.99 and $10, the half-off would be take on the $10 item.

    - Create an IPO chart for the problem, and then desk-check the algorithm twice. For the first desk-check, use 24.99 and 10 as the prices.

    13) Allenton Water Department wants a program that calculates a customer's monthly water bill. The clerk will enter the current and previous meter readings. The program should calculate and display the number of gallons of water used and the total charge for the water. The charge for the water is $7 per 1000 gallons. However, there is a minimum charge of $16.67.

    - Create an IPO chart for the problem, and then desk-check the algorithm twice. For the first desk-check, use 13000 and 16000 as the previous and current meter readings.

    IF YOU GUYS COULD HELP ME OUT WITH THESE TWO PROBLEMS I WOULD GREATLY APPRECIATE IT. HW IS DUE TMW MORNING!!!

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Pick one and start. What have you tried?
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Feb 2011
    Posts
    6
    I've tried both. I can't quite grasp this whole thing because this is my first actual C++ programming class with not much intro ahead of it.

    #include <iostream>
    #include <iomanip>
    using namespace std;

    int main()
    {
    //declare variables
    double totalBill = 0.0;
    double meterTwo = 0.0;
    double gallonsUsed = 0.0;
    char pricePerGallon = ' ';
    double total = 0.0;


    //enter input items
    cout << "Meter One: ";
    cin >> meterOne;
    cout << "Meter Two: ";
    cin >> meterTwo;
    cout << "Price Per Gallon: ";
    cin >> pricePerGallon

    thats where i'm at for #13 but its ALL wrong =/

    and this is my #12:

    #include <iostream>
    #include <iomanip>
    using namespace std;

    int main()
    {
    //declare variables
    double firstShoe = 0.0;
    double secondShoe = 0.0;
    char halfOff = ' ';
    double total = 0.0;


    //enter input items
    cout << "First Shoe: ";
    cin >> firstShoe;
    cout << "Second Shoe: ";
    cin >> secondShoe;
    cout << "Half Off (Y or N): ";
    cin >> halfOff;



    //calculate the total
    total = firstShoe + secondShoe / halfOff;
    if (toupper(halfOff)=='Y')
    total = total +5;

    but it's wrong as well...
    I really need A LOT of help

  4. #4
    Registered User
    Join Date
    Feb 2011
    Posts
    6
    Can someone please help me!?!?!

  5. #5
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,218
    Please use CODE tags to make your code more readable.

    You're close on "#13". The pricePerGallon is given for you at .007 ($7/1000 gallons). You don't have to prompt the user for the value and its type should not be a char, but a double, and then set to .007.

    Then you just have to subtract meterOne from meterTwo (assuming meterTwo is the current reading). Then use the formula: cost = difference * pricePerGallon. Then check if the cost is less than 16.67, set the cost to 16.67.
    Last edited by itsme86; 02-22-2011 at 12:15 PM.
    If you understand what you're doing, you're not learning anything.

  6. #6
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,218
    As for "#12", use this logic:
    Code:
    if costOfItemOne is less than costOfItemTwo
      costOfItemOne equals costOfItemOne divided by 2
    else
      costOfItemTwo equals costOfItemTwo divided by 2
    If you understand what you're doing, you're not learning anything.

  7. #7
    Registered User
    Join Date
    Feb 2011
    Posts
    6
    Quote Originally Posted by itsme86 View Post
    Please use CODE tags to make your code more readable.

    You're close on "#13". The pricePerGallon is given for you at .007 ($7/1000 gallons). You don't have to prompt the user for the value and its type should not be a char, but a double, and then set to .007.

    Then you just have to subtract meterTwo from meterOne (assuming meterTwo is the current reading). Then use the formula: cost = difference * pricePerGallon. Then check if the cost is less than 16.67, set the cost to 16.67.
    could you modify my code with what you're saying to help me understand that better?
    and sorry about the code tags

  8. #8
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,218
    Quote Originally Posted by NikeLover View Post
    could you modify my code with what you're saying to help me understand that better?
    and sorry about the code tags
    I won't do your homework for you. Give it a shot using the suggestions and post your attempt if you're unable to do it. Your first step would probably be to read the instructions better. Why would you ask the user for the price per gallon if the value is given to you as part of the problem in the first place?
    If you understand what you're doing, you're not learning anything.

  9. #9
    Registered User
    Join Date
    Feb 2011
    Posts
    6
    Code:
    #include <iostream>
    #include <iomanip>
    using namespace std;
    
    int main()
    {
    	//declare variables
    	double meterOne = 0.0;
    	double meterTwo = 0.0;
    	double gallonsUsed = 0.0;
    	double pricePerGallon = ' ';
        double total = 0.0;
    
    
    	//enter input items 
    	cout << "Meter One: ";
    	cin >> meterOne;
    	cout << "Meter Two: ";
    	cin >> meterTwo;
    	cout << "Price Per Gallon: ";
    	cin >> pricePerGallon
    
    	
    
    
    	//calculate the total
    	;gallonsUsed = meterTwo - meterOne * pricePerGallon;
    	if (toupper(pricePerGallon)=='N')
    		total = total +7;
    
    
    	//display total
    	cout << fixed << setprecision(2);
    	cout << "Total: $" << total << endl;
    
    	return 0;
    }
    are the variables correct?
    are the input items correct?
    am i getting closer?

  10. #10
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    Did you compile it?
    Does it compile OK, or give you error messages?

    Did you run it?
    What did you type in? Does the answer look correct?

    Being able to do these things are all part of the skills required.
    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.

  11. #11
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,218
    Quote Originally Posted by NikeLover View Post
    Code:
    #include <iostream>
    #include <iomanip>
    using namespace std;
    
    int main()
    {
    	//declare variables
    	double meterOne = 0.0;
    	double meterTwo = 0.0;
    	double gallonsUsed = 0.0;
    	double pricePerGallon = ' ';
        double total = 0.0;
    
    
    	//enter input items 
    	cout << "Meter One: ";
    	cin >> meterOne;
    	cout << "Meter Two: ";
    	cin >> meterTwo;
    	cout << "Price Per Gallon: ";
    	cin >> pricePerGallon
    
    	
    
    
    	//calculate the total
    	;gallonsUsed = meterTwo - meterOne * pricePerGallon;
    	if (toupper(pricePerGallon)=='N')
    		total = total +7;
    
    
    	//display total
    	cout << fixed << setprecision(2);
    	cout << "Total: $" << total << endl;
    
    	return 0;
    }
    are the variables correct?
    are the input items correct?
    am i getting closer?
    You're still asking the user for the price per gallon. You already know what it is ($7/1000 gallons) so why are you prompting the user for it?

    Also, watch your order of operations here: gallonsUsed = meterTwo - meterOne * pricePerGallon. Multiplication has higher precedence than subtraction so you'll need to use parentheses to force the precedence you want: gallonsUsed = (meterTwo - meterOne) * pricePerGallon. But why are you setting it to that anyway? That's calculating cost, but you're assigning it to a variable called gallonsUsed. You are supposed to print out the gallonsUsed separately, so I'd store that in its own variable and then use it in the cost calculation: gallonsUsed = meterTwo - meterOne; cost = gallonsUsed * pricePerGallon.
    If you understand what you're doing, you're not learning anything.

  12. #12
    Registered User
    Join Date
    Feb 2011
    Posts
    6
    didn't figure it out. just gonna move on.

  13. #13
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Bad idea. That seems to suggest you don't understand logic, which is the building block of alls things in programming. Without it, you will get nowhere.
    Write a flow chart or pseudo code to figure out the flow and fix it until it matches the logic or flow you want. An important exercise, and will give you a lot.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Common Problems
    By WolfPack in forum C Programming
    Replies: 4
    Last Post: 01-28-2003, 06:38 PM
  2. tile colliision detection problems
    By werdy666 in forum Game Programming
    Replies: 1
    Last Post: 10-23-2002, 09:26 PM
  3. Coding Problems
    By RpiMatty in forum C++ Programming
    Replies: 12
    Last Post: 01-06-2002, 02:47 AM
  4. Problems with my RPG app
    By valar_king in forum Game Programming
    Replies: 1
    Last Post: 12-15-2001, 08:07 PM
  5. problems with too many warning messages?
    By Isometric in forum C Programming
    Replies: 9
    Last Post: 11-25-2001, 01:23 AM