Hello everyone, I began working with C++ few months ago and I'm trying to create a simple shopping program that would ask the user to enter their information (such as name date and address) and then it would take the user through a simple shopping experience where the user enters the qty of the listed items and it generates an invoice in the end with the total sum. Unfortunately I am having a hard time debugging it...I would really appreciate your help.
Here is what i have so far:
Who ever was attached to "closed account" made two good points, but I did not even get that far when I tested the program.
On line 14 you use "cin" to get the date and that should work, but some day it might become a problem. And on line 16 you also use "cin" to get an address and that is a problem because an address will most likely contain spaces and "cin" will extract to the first white space or a "\n" which ever comes first leaving the remainder in the buffer, so the next call to "cin" will extract from what is left in the buffer not the keyboard thus putting incorrect information into the next variables. Thus the inputs at line 21 and 23 will come from the input buffer not the keyboard essentially putting incorrect information into your array. And this could also bypass line 29 and end the while loop finishing the program printing out bad information.
On line 14 I would suggest using std::getline(std::cin, date); and the same on line 16. You should also change char date[100]; to std::string date{ "" }; and the same with address. You will find that std::string will work the same as the old style char array yet offers more flexibility than the char array.
Also on line 9 I would suggest that you initialize all your variables before you us them.
Some where around line 31 you need to check the value of "i" so as not to out of bounds with the array.
In line 32 you could write the "while" as while(toupper(more) == 'Y'); or you could use tolower(). Either way will work.
I will need to make some changes and do so more testing before I can go any farther.
line 25 I changed getUnitprice(invoice[i][0]) to getUnitprice(static_cast<int> (invoice[i][0])) because you were trying to send a double to a function that requires an int. This gave me a compiler warning, but no error.
After line 31 I added if (i > 9) more = 'N'; to keep the loop from going out of bounds with the array.
Line 40 changed "tot" form an int to a double.
Line 44 changed l < 6 to l < 4 because the second dimension is only 4 i.e., 0 to 3 6 is out of bounds.