C++ math question

This is a discussion on C++ math question within the C++ Programming forums, part of the General Programming Boards category; I have a math problem. I have 3 categories of customers: old new temporary They can purchase books at the ...

  1. #1
    Registered User
    Join Date
    Aug 2005
    Posts
    15

    C++ math question

    I have a math problem. I have 3 categories of customers:
    old
    new
    temporary

    They can purchase books at the following rates:

    old: 1-5 purchased = 50.00 each
    6 or more = 45.00 each

    new: 1-5 purchased = 35.00 each
    6 or more = 30.00 each

    temporary: 1-5 purchased = 20.00 each
    6 or more = 15.00 each

    Thanks

  2. #2
    ^ Read Backwards^
    Join Date
    Sep 2005
    Location
    Earth
    Posts
    282
    So whats the math problem?

  3. #3
    Registered User
    Join Date
    Aug 2005
    Posts
    15
    Do I use if / else or is there a simpler way to do it with an equation?

  4. #4
    ^ Read Backwards^
    Join Date
    Sep 2005
    Location
    Earth
    Posts
    282
    Sure, if-else will work here.

    Making some assumptions on what you are doing and how, it might look something like this:


    Code:
    if (number_of_books_purchased < 6)
    {
    
    
    	old_total = (number_of_books_purchased * 50);
    	new_total = (number_of_books_purchased * 35);
    	temp_total = (number_of_books_purchased * 20);
    
    }
    
    else 
    
    {
            old_total = (number_of_books_purchased * 45);
    	new_total = (number_of_books_purchased * 30);
    	temp_total = (number_of_books_purchased * 15);
    
    }

    This puts them in a variable_total all on its own (which you would have to declare). Do not know if that is what you wanted/how you wanted to code, but this is far from the only way.

    But uhh, why are you ripping off all your old and faithfull customers by making them pay so much more!

  5. #5
    Registered User
    Join Date
    Aug 2005
    Posts
    15
    That is exactly what I was looking for. I thought if/else would be o.k. but was not sure.
    Not really ripping off old faithful this was just some random numbers.
    Thanks

  6. #6
    Registered User major_small's Avatar
    Join Date
    May 2003
    Posts
    2,787
    you'll find that usually a good way to start out is to write out exactly what it is you need to do in english. when you've done that, you'll usually find it's easy to translate that into code.

    the english version is called psuedocode, and what you're doing is devising an algorithm.
    Join is in our Unofficial Cprog IRC channel
    Server: irc.phoenixradio.org
    Channel: #Tech


    Team Cprog Folding@Home: Team #43476
    Download it Here
    Detailed Stats Here
    More Detailed Stats
    52 Members so far, are YOU a member?
    Current team score: 1223226 (ranked 374 of 45152)

    The CBoard team is doing better than 99.16% of the other teams
    Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)

    Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT

  7. #7
    ^ Read Backwards^
    Join Date
    Sep 2005
    Location
    Earth
    Posts
    282
    the english version is called psuedocode, and what you're doing is devising an algorithm.
    What is it called when it is in French?


    wait for it.....wait for it...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. another exercise question
    By luigi40 in forum C# Programming
    Replies: 3
    Last Post: 11-28-2005, 02:52 PM
  2. opengl DC question
    By SAMSAM in forum Game Programming
    Replies: 6
    Last Post: 02-26-2003, 08:22 PM
  3. More a math question than an algorithm
    By Gustaff in forum C Programming
    Replies: 1
    Last Post: 01-28-2003, 12:10 PM
  4. Stupid Math Question....really stupid
    By ToLazytoSignIn in forum A Brief History of Cprogramming.com
    Replies: 9
    Last Post: 01-16-2003, 06:36 PM
  5. Math Question
    By DarkEldar77 in forum C++ Programming
    Replies: 2
    Last Post: 09-17-2001, 12:52 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21