Thread: I am working on homework regarding C++ selection programming and need help.

  1. #16
    Registered User Alpo's Avatar
    Join Date
    Apr 2014
    Posts
    877
    Some different ways to do it:

    Code:
    total /= (discountHalfOff == 'y' ? 2 : 1);
    Code:
    if (discountHalfOff == 'y') {
        total /= 2;
    }
    Code:
    if (discountHalfOff == 'y') {
        total = total / 2; // Same as: total /= 2
    }
    We always save the value of half of total in the total variable, but we don't want to use the value of 'discountHalfOff' in the calculation. We just use discountHalfOff to check for the 'y' value, in which case we take half off the value of total.

    Quote Originally Posted by setleaf
    If you want to keep the current variables you have then you need to initialize a discountPercentage with ".50". Then read the char into discountHalfOff. As for your if statement it's if discountHalfOff=='Y' then total = itemOnePrice + itemTwoPrice / discountPercentage, and if not then just add up price one and price two.
    Are you trying to rip me off?! lol (I think you meant to multiply :P).
    WndProc = (2[b] || !(2[b])) ? SufferNobly : TakeArms;

  2. #17
    Registered User
    Join Date
    Mar 2015
    Posts
    184
    It is not clear if the discount applies to the total cost or to the second item. OP may even need to check if it should apply to the cheapest item (like in most real shops).

    But I think the problem is more about the mathematical nature than about the programming. No offense but most primary school students should be able to come up with two correct formulas for total.
    Last edited by jiggunjer; 03-22-2015 at 12:28 AM.

  3. #18
    Registered User setleaf's Avatar
    Join Date
    Dec 2014
    Location
    Virginia/USA
    Posts
    47
    Quote Originally Posted by Alpo View Post
    Are you trying to rip me off?! lol (I think you meant to multiply :P).
    Oops! Yeah I totally meant to multiply.

  4. #19
    Registered User
    Join Date
    Mar 2015
    Posts
    12
    my program was successful after I fixed the glitches. thank you

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. menu selection with arrow key in c programming
    By slyern in forum C Programming
    Replies: 1
    Last Post: 06-22-2014, 08:37 AM
  2. Working on homework, hit a snag
    By devisezni in forum C++ Programming
    Replies: 11
    Last Post: 09-18-2012, 03:14 PM
  3. Replies: 4
    Last Post: 12-11-2011, 04:25 PM
  4. Replies: 5
    Last Post: 04-03-2011, 02:05 PM
  5. Working with Nested "Switch Multiple-Selection"
    By MAV_DevWantB in forum C Programming
    Replies: 5
    Last Post: 09-18-2009, 08:05 AM

Tags for this Thread