Hello,

I would like to know how you can keep running a function over and over again, so that it can keep adding the stored value. For example If Bob uses a program to purchase a ticket, lets say that Bob purchases 5 tickets out of 55 tickets (There's only 55 seats).So, now there is only 50 tickets left. Alice, comes and uses the program to purchase another 5 tickets. This will minus from the current value which is 50 and this will continue to happen until there's no tickets left and the program gives out an error message. How can I keep looping the function over and over again, so that different people can come and purchase any amount of tickets and then the program will take the quantity of the tickets and minus it from how many tickets there are left.

Thanks.

Recommended Answers

All 4 Replies

Use a loop. There are three kinds of loops: for loop, while loop, and do loop. Use the one that best fits the situation. Read this short tutorial

i usually use do{...}while(1);
1 is always true, therefore it will stay in the loop. if you want to get out of it, the command "break;" should do it.

Thanks for the replies, but could you show me what you mean?

Thanks again.

Thanks for the replies, but could you show me what you mean?

Thanks again.

if you code something like

int i;
do
{
    i++;
}
while(1);

it will jump into the do/while loop and start incrementing i (i++; -> i=i+1; ). after that it will look if the statment given in brackets is true or false. in c a true statement is 1 and a false one is 0. if the statement is true the loop will be looped once again, after that the statement is checked again.
you also could code while(i>0)... this also would be true for a start i=0;

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.