+ 3
----Errors in your code---- There's a lot wrong with your code, including: iteration, useless inclusion of string header (no uses for it in your code), efficiency and variable declaration (why declare long ints and doubles when you can use unsigned short and float? They're not large integers or real numbers with high precision) and most importantly that last else if, it's so broken that if I don't submit anything when running the code, total will be 5.35. You should also think of readability while coding, if you need to do that long of an else if then you know you did something wrong or didn't think about the problem long enough. ----How to solve them---- Since you've included string.h you can use its strcmp function to compare the input orders with available orders as so : !strcmp(order, "Pizza") -- logical ! because if they're different the returned value is 1 or -1 -- , saving you a lot of lines and time, plus, it's more readable than comparing char by char as you did in your solution. The input is one string so if you wanna read from it you should use sscanf(Orders + i, "format", Order) where i is the sum of all strings you've read (i += strlen(Order)) so you don't only read the first string before ' '. By the way, you don't need all those long ints and that extra double tax, you can do your problem by only using total, just do total += (price of available order / 6) and total += (float)(7 * total / 100). If you need more explanations, reply to this answer. If you really wanna keep your code that way (not recommended) check if it works when removing .2 in the last printf.
8th Jun 2020, 11:15 PM
Daveyyy
Daveyyy - avatar