Hi everyone! I'm having a very hard time figuring out how to make my Do-While statement work in this Traveltour program. It's looping but it doesn't store the inputs i made at the first loop i made. It can only solve for the latest inputs given. Can anyone please help me out here :
Not exactly sure what you mean, but you are changing these variables double fare,tax,total_amt; during the loop, so after the loop only the last values will remain in there.
If you want to store multiple entries in there you will have to use arrays - or one array of structs.
Then you can loop over the array(s) and get the data you need.
More info on arrays and structs:
http://cplusplus.com/doc/tutorial/arrays/
http://cplusplus.com/doc/tutorial/structures/
Yes, I want to store multiple entries for the values of fare and tax. Then sum them all up for the total amount. Do you think i should use the arrays? Thanks for the Help!
If you want to keep the remaining name, age, etc perhaps you should test to see if they are input (loop has gone through at least once successfully) and not reassign them? A simple example of what I'm talking about:
1 2 3 4 5 6 7 8 9 10
string name;
...
do
{
if(name.empty()) // first run;
{
cout << "\nEnter your name:"; // remember this will only take one word. If you want a full name with spaces between you'll need to use getline. This introduces other problems when you use getline and cin >> though.
cin >> name;
}
} while(...);
I was able to run this program and input name,age,etc. but when i Try to input ANOTHER data for the name,age, etc. it deletes the previous data i inserted. what i want to happen is to add the previous money values I inserted with the new value i inserted. Thanks for the help!
Someone please correct me if there's a better way.
It's also possible to make an array of structs using pointers, but I gather that's kind of dirty work.