store the quantity for selected type in a variable, multiply the cost for selected type with quantity, and store it separately , repeat the same for all selected items.By the way how are you planning to display your menu, i dont see any function calls in your main function :) , if u place some function calls in main, make sure u either declare or define ur functions before main() :)
alrite, the functions and planning are already taken care of, could be please rephrase your response, I mean, is there another way of getting one value at a time and manipulating it, for example for the above problem 3 3 5 5, how do I get each number and reference it to the menu list...thanks
#define cheese_cost 1.50
//define similar constants for others
int ShowMenu(){
int ch;
int icount_Cheese =0;
int icount_Butter =0;
int icount_Bread =0;
int icount_Jam =0;
int temp =0;
float total_cost =0;
while(1)
{
cout<<"1. Cheese $1.50\n";
cout<<"2. Butter $2.00\n";
cout<<"3. Bread $0.75\n";
cout<<"4. Jam $3.50\n";
cout<<"5. End of transaction\n";
cout<<endl;
cin>>ch;
switch(ch)
{
case 1: cout<<"enter the quantity for cheese";
cin>>temp;
icount_Cheese=temp+icount_Cheese;
break;
//similarly for other cases
case 5:total_cost=(icount_Cheese*cheese_cost)+//similarly for others;
return total_cost;
}
//end of switch
}
//end of for
return 0;
}
//end of menu
or you can calculate the total cost in a separate function to make it proper, just store the counts in an array or list , return the same.
Thanks that really helped alot,
Okay, what if instead of asking the user to enter the quantity for cheese, the program was changed
void ShowMenu(){
cout<<"1. Cheese $1.50\n";
cout<<"2. Butter $2.00\n";
cout<<"3. Bread $0.75\n";
cout<<"4. Jam $3.50\n";
cout<<"5. End of transaction\n";
cout<<endl;
}
the numbers 1,2,3,4 and 5 represents the different options, what if the user wanted Cheese and Bread and pressed 1 3 as their choice which represent Cheese and Bread, how would you calculate for bread and cheese....is it done separately or together...thanks
Oh and how would this problem be solved using arrays...???
How would u find out the quantity?? assuming u are not interested in quantity. u can either calculate independently or togather.
the code i gave u considers quantity as well, and calculates the whole cost
at once.
Okay, if the user enters 2233 that means that the user wants 2 Jams and 2 Bread, how would I calculate this...meaning how would I get the program to get the cost for jam(3.50 + 3.50) and the cost for bread(0.75 + 0.75). The value the user enters also acts as the quantity for the items. In the case as mentioned above the user wants 2 jams and 2 bread..makes sense??......thanks
Food for thoughts you can improve your code such that if the user input an amount of money that's greater than the initial amount he should be able to get some change. For instance if the cheese costs $5 and the user input $6.25 you code should be able to display the change($1.25) that has to be returned.
Thanks...
but how do you actually get each value entered by the user and calculate the cost...I mean for 2233 how do I generate a code to go from 2 then to 2 then 3 and finally to 3, getting the relevant information and calculating the total.