The Frozen Tongue Ice Cream Shop sells six flavors of ice cream: chocolate, vanilla, strawberry, mint, rocky road, and mocha. The shop wants a program that tracks how many scoops of each flavor are sold each day. The console input for each transaction will be the name of a flavor followed by how many scoops of that flavor were sold in that transaction: example of initial output: Enter the flavor of the scoops sold (STOP to exit): vanilla Enter how many scoops were sold: 3 If the user enters a flavor that doesn't match any of the known flavors, the program should display an error message. The user should be allowed to enter as many transactions as desired, and each flavor will likely appear in more than one transaction. Once the user enters "STOP", the program should terminate, and the program should display how many scoops of each flavor were tallied in the program run: DAILY SCOOP REPORT: Chocolate: 58 Vanilla: 65 Strawberry: 49 Mint: 23 Rocky Road: 37 Mocha: 31 One way to make sure that the scoops are added to the proper flavor counter is to have a series of decision statements comparing the user's input to each flavor. Another approach would be to use parallel arrays, with an array of strings storing the name of the each flavor and an array of integers storing the count for each flavor at the same index as the flavor name in the other array. Write your code so that it handles the flavor name with a space and so that the user's input will be matched to the correct flavor no matter what type of capitalization is used. Position the output so that the number of scoops for each flavor is right-aligned (assume that the demand for flavors can vary, so the number of scoops for any flavor may be between one and three digits): Example output: DAILY SCOOP REPORT: Chocolate: 92 Vanilla: 103 Strawberry: 89 Mint: 8 Rocky Road: 76 Mocha: 64 |
|
|
|
|
getline(cin, flavor);
if(!flavor.compare("stop") // notice i have used '!' as this function returns 0 if both strings are the same
On the same topic, you have use single quotes for a word; single quotes are only used for single characters. Also, in your assignment brief it says accept flavour names no matter how they are written(capitalization and what not) so I personally would take any input and force all letters to lower case and then do the if statement. Do as you see fit though
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Remembering that the comparison operations for strings in C++ use lexicographic ordering, so if a user enters a flavor name with an uppercase letter, the name will not match. Write your code so that the user's input will be matched to the correct flavor no matter what type of capitalization is used. |
|
|
if (flavor_input == "STOP" || flavor_input == "Stop")
to use the compare function given in the string class, and don't compare this way whether you're using string objects or C-Strings!!!