Task Description
The menu for the local Lone Star Diner is as follows:
COFFEE – $0.50
SODA - $1.00
MILKSHAKE - $2.13
PANCAKES - $3.25
WAFFLES - $3.92
HAMBURGER – $4.01
PASTA - $4.44
HOTDOG - $2.98
CHIPS - $0.65
FRIES - $0.99
Write a program that takes a given list of menu items that have been ordered and displays the total bill.
Program Input
The customer’s order is contained in an input file (c:\codewars\prob11.in). The input file will contain a list
of items ordered by the customer. Each item will be on a separate line. “END” will signify the end of the
order.
COFFEE
COFFEE
WAFFLES
PASTA
END
Oh, and by the way, when the diner gets really busy, the waiters get a little sloppy with the order entry so
there may be a typo (or not) in each line of the order. A typo will only consist of a single missing letter or
having a single wrong letter per each item name, but not both. For example:
CONFEE
OFFEE
WAIFLES
PASTE
END
You can assume END will always be spelled correctly.
Program Output
The total cost of the order, as follows:
Your total is $9.36
I have gotten past the part of the correct problem, where my program works fine and gets the total. The trouble i am having is with the incorrect word plus the missing letter. I know its going to involve string manipulation.
Here is the code i have so far, and yes i know else if statement wasnt efficient.
cout<<"Your total is: "<<totalCost<<endl;
return 0;
}
and as the problem states
"Oh, and by the way, when the diner gets really busy, the waiters get a little sloppy with the order entry so
there may be a typo (or not) in each line of the order. A typo will only consist of a single missing letter or
having a single wrong letter per each item name, but not both"
so as you see in the program, it takes every line of my input file, and checks it.
I have no idea how to approach it, any ideas?
Don't forget to normalize your input. You'll want all of the letters you are testing against each other to be in the same case to cut the number of checks you have to do in half. "std::tolower()" should be adequate: http://en.cppreference.com/w/cpp/string/byte/tolower
First, let me congratulate you. Your code is well written for a beginner. You recognized that the "and by the way" part is an extension of the problem and you solved the easy part first. You also recognized that the lookup function is inefficient. You have a knack for programming.
You can make the code a little cleaner by moving the menu data into an array of structures and then write a function to find the appropriate entry in the menu:
If you have findItem() then you can easily add the tolower() code that Computergeek01 suggested, along with the Levenshstein distance code that JLBorges suggested.