CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Mar 2014
    Posts
    3

    New to C++ need help with assignment.

    This is my assignment and I got this far with it so far. I was curious if anyone could give me a hint as to how I could solve the problem of adding 1 extra bagel per every dozen bagels and also giving the best price to the costumer if they buy 10 bagels it would cost them $4.60 but 13 would cost them $3.80 which is a better price for the customer and they save 0.80 cents. I feel like im really close but this is a real head scratcher for me I would really appreciate any hints on this subject. Thanks

    This is the assignment: http://www.cs.csi.cuny.edu/~imberman...s%20bagels.htm

    Code:
    #include <iostream>
    #include <iomanip>
    
    using namespace std;
    
    int main()
    
    {
    	int bagels, half_dozen, dozen, temp_bagels1, temp_bagels2, total_bagels;
    	double price_bagel, price_half, price_dozen, total_price, price_diff;
    
    	half_dozen = 6;
    	dozen = 12;
    	price_bagel = 0.50;
    	price_half = 2.60;
    	price_dozen = 3.80;
    
    	cout << "How many bagels would you like today? ";
    	cin >> bagels;
    	cout << "Thank you for your order." << endl;
    
    	if (bagels < half_dozen)
    		total_price = bagels * price_bagel;
    
    	else if (bagels < dozen)
    	{
    		temp_bagels1 = bagels / half_dozen;
    		total_price = temp_bagels1 * price_half;
    		temp_bagels1 = bagels % half_dozen;
    		total_price = total_price + temp_bagels1 * price_bagel;
    		cout << fixed << showpoint << setprecision(2);
    		cout << total_price << endl;
    
    	}
    	else if (bagels >= dozen)
    	{
    		temp_bagels1 = bagels / dozen;
    		total_price = temp_bagels1 * price_dozen;
    		temp_bagels1 = bagels % dozen;
    		temp_bagels2 = temp_bagels1 / half_dozen;
    		total_price = total_price + temp_bagels2 * price_half;
    		temp_bagels2 = temp_bagels1 % half_dozen;
    		total_price = total_price + temp_bagels2 * price_bagel;
    		cout << fixed << showpoint << setprecision(2);
    		cout << total_price << endl;
    		cout << total_bagels << endl;
    
    	}
    	return 0;
    
    }

  2. #2
    Join Date
    Apr 1999
    Posts
    27,449

    Re: New to C++ need help with assignment.

    So what is the question that you have? Just posting the assignment, code, and asking for "hints" doesn't tell us exactly what you are having problems with.

    Regards,

    Paul McKenzie

  3. #3
    Join Date
    Mar 2014
    Posts
    3

    Re: New to C++ need help with assignment.

    Well I'm not sure how to write the part of the assignment that will give the customer 1 extra bagel per every down bagels and also the best price as the example shows where the customer buys 10 bagels.

  4. #4
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,825

    Re: New to C++ need help with assignment.

    At the risk of sounding non-helpful (and I'm trying to be helpful without actually doing the work for you - see http://forums.codeguru.com/showthrea...ork-assignment), this is not a coding issue but an algorithm/design issue. Before coding a program, you should design it by expressing in English (or other natural language) how the program is to function - ie how would you do this using paper and pen.

    Code:
    determine input requirements
    determine output requirements
    determine algorithms needed
    do {
         design program
         code program
         test program
         debug program
    } while program_not_working
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

  5. #5
    Join Date
    Mar 2014
    Posts
    3

    Re: New to C++ need help with assignment.

    Thanks I'll give that a try. I'm just new to c++ so I need to work on my algorithm forming skills lol.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured