I kinda know what is the issue, it means if an user does not select one of the options, the value of that said "tp" would be undefined because the user did not select any quantity.
Problem is, i do not know how to fix this. How do i make it so that "tp1,2,3,4" will be defined no matter if the user chooses it or not?
Or just have one variable, called like "tp" or something, since you never seen to use more than one variable at a time. You can also just have one "quantity" variable.
this isn't the full code so the second part is not possible as there is a part in the code that i did not put here where the user is allowed to choose additional product from the list.
1 2
printf("\nDo you want to add-on?(1-Yes, 2-No) : ");
scanf("%lf", &r);
@Ganado, I tried your first recommendation and it worked (thanks alot).
I have another question, at the moment it is just calculating the total bill one by one but that is not what I want when there is an "add on", I want it so that the current selected product price is stored already + the total price of the added on products.
Yes!! thank you very much. works good now.
really appreciate it
btw how did you know i was re-defining r? i did not even put that part of the code in (i redefined it like you said before the "do"), thanks for letting me know too
What I mean is, in your loop, you define "double r;", but then the condition for your loop is "while (r == 1);". If you wish to use r as the condition for the while loop, it has to be defined outside of the while loop itself.
For example, the following will not compile:
1 2 3 4 5 6 7 8
int main()
{
do
{
double r = 3;
}
while (r == 2);
}
7:12: error: 'r' was not declared in this scope
The following will compile:
1 2 3 4 5 6 7 8 9 10 11 12 13
// Example program
#include <stdio.h>
int main()
{
double r = 3;
do
{
printf("loop entered\n");
r--;
}
while (r == 2);
}
I just realized when using the function you gave me totalbill += (tp1 + tp2 + tp3 + tp4);, it seems like the program is adding itself again whenever i select a different add .on
If you're running an issue like that, then you need to split up that summation code.
Still keep a "totalbill" variable, but remove the totalbill += tp1 + tp2 + tp3 + tp4 line, and you should do something like this instead:
i split up the summation code but i still have to keep the last line right? (ps: i removed the + from the "+=" that was there before) totalbill = (tp1 + tp2 + tp3 + tp4);
tried running it, it works now and it doesnt add itself everytime.