Need help with using a loop

I have been given to do a simple ATM project which is containing of getting a number of notes in the ATM (100, 500, 1000). Get the withdrawal of money and show the number of note. Here what i got so far. I may need to use a loop but i am not sure how to put it into this.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include <stdio.h>
#include <conio.h>

int main()
{

	int a=10, b=10, c=10;
	int q;
	printf("Start....");
	printf("\n#100  : %d",a);
	printf("\n#500  : %d",b);
	printf("\n#1000 : %d",c);
	printf("\nPerson-Withdraw: ");
	scanf("%d", &q);

		if (q %100 != 0)
		{
		printf("Cannot Pay !!");
		}
		else if (q %500 == 0) 
		{
		c=c-(q/1000);
		b=b-(((q/100)%10))/5;
		printf("\n#100  : %d",a);
		printf("\n#500  : %d",b);
		printf("\n#1000 : %d",c);
		}
		else 
		{
		c=c-(q/1000);
		b=b-((q%1000)/500);
		a=a-((q%500))/100;
		printf("\n#100  : %d",a);
		printf("\n#500  : %d",b);
		printf("\n#1000 : %d",c);
		}
	getch();
	return 0;
}


But the problem is i don't know how to make the code continue with the process with the amount of notes that is left from the previous input. The program will just stop but i really want it to be able to input new withdrawal amount so that it can decrease the note each time i withdrawal the money. Please help
Use a while(true) loop with a break statement.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include <stdio.h>
#include <conio.h>

int main()
{

	int a=10, b=10, c=10;
	int q;
	printf("Enter '-1' to stop withdrawal");
	printf("Start....");
	while(true){
		printf("\n#100  : %d",a);
		printf("\n#500  : %d",b);
		printf("\n#1000 : %d",c);
		printf("\nPerson-Withdraw: ");
		scanf("%d", &q);
		if(q==-1) break;	// break out of loop

			if (q %100 != 0)
			{
			printf("Cannot Pay !!");
			}
			else if (q %500 == 0) 
			{
			c=c-(q/1000);
			b=b-(((q/100)%10))/5;
			printf("\n#100  : %d",a);
			printf("\n#500  : %d",b);
			printf("\n#1000 : %d",c);
			}
			else 
			{
			c=c-(q/1000);
			b=b-((q%1000)/500);
			a=a-((q%500))/100;
			printf("\n#100  : %d",a);
			printf("\n#500  : %d",b);
			printf("\n#1000 : %d",c);
			}
	}
	getch();
	return 0;
}
Topic archived. No new replies allowed.