Loop

Good Day .. I'm new to the forum ..
New to C++ either .. I'm having a problem regarding the while loop ..

I've been trying to make an ATM system .. But I can't continue further for the other cases because whenever I try the loop for going back to the menu isn't working .. Here's my code ..

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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include<stdio.h>
#include<conio.h>

void main()
{
	int pin, menu, vBal;
	float cBal=5000, sBal=10000;
	char ans='Y';
clrscr();

		gotoxy(20,5);printf("******** Welcome to IIC Bank Express ********");
		gotoxy(20,15);printf("Enter Pincode: ");
		scanf("%d", &pin);
	if (pin==1234)
	{
		while(ans=='Y')
		{
		clrscr();
				gotoxy(20,5);printf("****** MENU ******");
				gotoxy(20,7);printf("[1]Balance Inquiry");
				gotoxy(20,9);printf("[2]Cash Withdrawal");
				gotoxy(20,11);printf("[3]Deposit");
				gotoxy(20,13);printf("[4]Fast Cash");
				gotoxy(20,15);printf("[5]Payments");
				gotoxy(20,17);printf("[6]Others");
				gotoxy(20,20);printf("Input choice: ");
				scanf("%d", &menu);
		clrscr();
				switch (menu)
				{
					case 1:
						gotoxy(20,5);printf("** Balance Inquiry **");
						gotoxy(20,7);printf("[1]Savings Account");
						gotoxy(20,9);printf("[2]Current Account");
						gotoxy(20,12);printf("Input Choice: ");
						scanf("%d", &vBal);	
		clrscr();
							if (vBal==1)
							{
							gotoxy(20,5);printf("** Savings Account **");
							gotoxy(20,8);printf("Current Balance is : %.2f", sBal);
							}
							else
							{
							gotoxy(20,5);printf("** Current Account **");
							gotoxy(20,8);printf("Current Balance is : %.2f", cBal);
							}
					break;
					default:
							printf("ERROR");
				}
						gotoxy(20,11);printf("Would like to make another transaction (Y/N): ");
						scanf("%c%s", &ans);	
						getch();
		}				
	}
}


Any quick response is much appreciated ..

thanks
try to make ur loop like this :

1
2
3
4
5
6
7
8
9
10
11
12

#include<iostream>
#include<conio.h>
using namespace std;
void main()
{
	char y;
	do
	{
	cout<<"Waaaaaaaagh!!!11!!!11!oneone"<<endl;
	}while(getch()=='y');
}


but be aware that this way if the user presses the wrong button, then the program closes without him wanting, so u should first chech if get inputs 'Y' for continue or 'N' for closing and if he presses something else, then output something like " u pressed the wrong button"
without
 
char y;
man, i should really check my post before submiting it, the grammar in the last one was horrible, sorry
You should also try the edit button. It looks like a little notepad near the time of your post. EDIT: your name or title of poster.
Last edited on
aha, thx, i didnt see that one, hehe every day u learn something new ^^
Topic archived. No new replies allowed.