My program calls a funtion which adds 10% tax onto a number that is given by the user. The function returns that value and then it gets printed thats easy.
However I need the user to be able to then enter another price that gets sent to the function and returned. Then I need the program to add all of the values up and print them out.
I am assuming I need to use an array for this. But im not sure where to put the array. Here is the relivant code.
while(pre_tax_value!="the number you want your program to stop with") // for example -1
{
eachValue=tax_Calculator(pre_tax_value);
sum+=eachValue;
cout<<"give another number to calculate its tax"; cin>>pre_tax_value;
} //while
in that case though, you have to check the number you enter with an if.
for example: in this case the number (you want to calculate its tax) cant be a negative number as u cant have taxes from negative numbers.. its a logic fault. so "-1" isnt that corrent in this case. You could use instead a big number for example 9999. and declare you variable as unsigned double (unsigned variables can only be >=0)
I wasn clear. I dont want the program to stop when a certain number is entered. The program is a Retail Shop program. You enter and Item give it a value then enter another item. I need it to add all those items up.
The program has to add up all the entered After Tax Values. There are infinite number of Entries. So i need my tax function to return individual After Tax Values and store them in an array. So I can then add up all the different values in my array.
Does that make more sense? Sorry im trying to be as descriptive as i can.
the method i posted above does that..
sum variable has the total cost you're talking about.
you can pick a number for your while that will never be one of those numbers you enter and your while will never stop.
you can print your sum with a cout<<"sum is:"<<sum<<endl; inside your while everytime u insert another number and thats all you can do if you dont know the excact number of your entries or if your program never stops.
i dont think you can use an array as you dont know the number of the values you will insert, as u said they will be infinite. i might be wrong though.