Thread: Need advice on umm.. variable number of variables haha.

  1. #1
    Registered User
    Join Date
    Nov 2009
    Posts
    7

    Need advice on umm.. variable number of variables haha.

    Sorry couldnt think of a better title haha. But anyways, I want to make a program for my mother to help my mom with her make-up business. She makes her own from scratch. I wanted to make a calculator to help her convert her recipes into a bigger/smaller quantity. I know all the calculations and can probably handle the rest of the code. But the problem I am having is that there is a different number of ingredients for each color.

    For example, some may have just like Mica, Titanium Dioxide, and Mica. While some may have upwards of 9 ingredients.

    So where should I look to find a method for this?

    Thank you all =)

  2. #2
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,612
    Use a file record of comma separated values. For example, make a spreadsheet with the ingredients and save it as a CSV file.

  3. #3
    Registered User
    Join Date
    Nov 2009
    Posts
    7
    I don't see how that helps. I don't know anything about CSV. C++ has just been a hobby of mine for awhile and I just passed a 201 class in college on C++ so Im more or less beginner-intermediate level

  4. #4
    Registered User jeffcobb's Avatar
    Join Date
    Dec 2009
    Location
    Henderson, NV
    Posts
    875
    Well giving this about zero seconds of thought I would reach for the database solution where you have one table with fields in it like:
    ID, Name, Vendor, AmtInStock, WholesaleCost, RetailCost

    Where ID is just an incrementing value as a key to the table, Name is like 'Mica' etc, AmtInStock is how much you have, Vendor is where you get it from (so that when AmtInStock gets below a certain value you can automatically reorder), wholesale and retail prices can help with pricing and cost projections.

    Then if you know no "recipe" for makeup is greater than 10 items you could have another table with:
    makeupID, Name, Item1, Item2 etc

    Where makeupID is just like ID in the ingredients table but for finished makeup items, Name is obvious and Item1, Item2, etc are just IDs of different things from the ingredients table. This has the benefits of being simple with the drawback of wasting space. There are many techniques for managing this but they go beyond the scope of this thread.

    Now another way you could lay out the main table (but would require custom code on your part) would be to construct the main table with variable-length records where you read the table like a stream:
    ID|Name|NumberOfIngredients|Item1|Item2| etc
    Where one record might look like:
    001|"FooMakeup"|2|0002|0007
    and another might be:
    002|"BarMakeup"|4|0043|0001|0002|0075
    So there is no wasted space but you need to custom-parse the records. After looking at it, in both cases you would need an amount per ingredient field to know how much to stick in but that is an exercise for the reader...
    C/C++ Environment: GNU CC/Emacs
    Make system: CMake
    Debuggers: Valgrind/GDB

  5. #5
    Registered User jeffcobb's Avatar
    Join Date
    Dec 2009
    Location
    Henderson, NV
    Posts
    875
    CSV just means comma-separated values, another twist on the second suggestion I had only I used the pipe ('|') to separate my values...but if you know nothing of CSV then my suggestions are not going to be much help either...sorry.
    C/C++ Environment: GNU CC/Emacs
    Make system: CMake
    Debuggers: Valgrind/GDB

  6. #6
    Registered User
    Join Date
    Nov 2009
    Posts
    7
    Well heres an example of what I want it to do.

    Example Recipe:
    23.44g Colorna Blue
    9.92g Black Oxide
    1.75g Kaolin Clay

    which is about 35g or a like 1.25oz. She always asks me to make calculations to make it like an 8oz recipe or different, sometimes she needs like 2.5oz 6.25oz ect. But in order to keep the same color the recipes need to stay in proportion. I know the calculations like I said. I just need to know what do do for the random number of ingredients.

    It will just be a simple program prompt like:

    example:

    Enter number of ingredients: 5
    Enter output weight(oz): 2.5

    Enter name of Ingredient 1:
    Enter weight of ingredient 1:

    and so on and so on then output the recipe.

  7. #7
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,612
    Quote Originally Posted by ljrobison View Post
    I don't see how that helps. I don't know anything about CSV. C++ has just been a hobby of mine for awhile and I just passed a 201 class in college on C++ so Im more or less beginner-intermediate level
    it's just a regular text file with a different extension. Save it as txt or whatever if you're more comfortable.

    What you would go ahead and do is make a list of all the ingredients of some makeup and their measures.

    "Mica",10.5,"Titanium Dioxide",5.67,"Mica",12.34

    That way when you run the program, some information is available right away and you can convert measures as much as you want. The real work in this program would be maintaining the file. Which means reading a line for a type of makeup, etc. Or look into giving your family member a database instead of writing this yourself. Part of the reason I suggested CSV is because programs like Excel (for spreadsheets) and databases can understand it to an extent. You know, in case your program isn't as useful as you think.

  8. #8
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    CSV would definitely be the simplest solution. As an alternate route you could try ADO.NET in C# but that would require learning an entirely new language (even though you could learn basic C# in under a week).

  9. #9
    Registered User
    Join Date
    Nov 2009
    Posts
    7
    Yeah I worked on C# a bit when I wanted to get into the XNA framework. But not too intentsly yet. But Ill definitely take a look at both those suggestions.

  10. #10
    Registered User
    Join Date
    Apr 2006
    Posts
    2,149
    Use an std::map of ingredients mapped to quantities.

    Or make an ingredient a class that has a name, amount, and unit, and store a bunch of ingredients in a vector.
    It is too clear and so it is hard to see.
    A dunce once searched for fire with a lighted lantern.
    Had he known what fire was,
    He could have cooked his rice much sooner.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. callee cleanup and variable number of parameters
    By cyberfish in forum Tech Board
    Replies: 14
    Last Post: 07-28-2009, 07:19 PM
  2. Variable Properties vs Public Variables
    By Rainbowinblack in forum C# Programming
    Replies: 2
    Last Post: 02-19-2008, 01:48 PM
  3. Issue w/ Guess My Number Program
    By mkylman in forum C++ Programming
    Replies: 5
    Last Post: 08-23-2007, 01:31 AM
  4. A very long list of questions... maybe to long...
    By Ravens'sWrath in forum C Programming
    Replies: 16
    Last Post: 05-16-2007, 05:36 AM
  5. Array of boolean
    By DMaxJ in forum C++ Programming
    Replies: 11
    Last Post: 10-25-2001, 11:45 PM