Hey everyone this is my first post here, I am a beginner in c++.
I was solving the tasks I found on this website here: http://www.cplusplus.com/forum/articles/12974/
While I was doing the "cola machine" I wanted to do it "nightmare mode" and try to use all the things I I know about C++ till now.
User sees the beverages available.
Inserts money.
The Drinks that he can afford appear.
User enters the number of the drink he wants.
Drink is printed, the remaining money is returned if available.
It is very similar except the drinks have prices to relate to, how can I let the same drinks(array) contain a string and a char? Here is the code, which might help you understand better.
You could separate the different parts by some delimiter:
drinks[0] = "Club Soda:0.50";
Then you find where the ':' is within the string. Everything from the start, up to but not including the ':' is the drink name. Everything after ':' is the price.
This may be more work than using a struct or class though, but it will give you good exposure to string work.
@peter87
i know a little about structs, but i don't know how to apply what i learned about it till now.
@roberts
how can i use that if i want to cout the pre-':', or compare whats after the ';' with an int?
excuse my noobiness :)
then convert price to an float. You can't use decimals in integer data types unless you start working with fixed-point or BCD, then again, you're back to more work than is necessary.