Member Avatar for nani_amb

hi.. i'm having trouble with my project.. i keep getting "Unhandled Exception"

# include <conio.h>
# include <stdio.h>

class bank
{
float x;
	public:

	void deposit();
	void withdraw();
	void disp_det();
};

void bank::deposit()
{
float more;
printf(" enter the amount to deposit: ");
scanf("%f", more);
x += more;
}

void bank::withdraw()
{
float amt;
printf(" enter the amount to withdraw: ");
scanf("%f", amt);
x -= amt;
}

void bank::disp_det()
{
printf(" Account details");
printf(" Balance: P%f", x);
}

void main(void)
{
clrscr();
bank obj;
int choice  =1;
while (choice != 0 )
{
printf(" Enter 1. Deposit \n  2. Withdraw \n	3. See A/c Status");

switch(choice)
{

	case 1: obj.deposit();
		break;
	case 2 : obj.withdraw();
		break;
	case 3: obj.disp_det();
		break;

}
}
getch();
}

can anyone tell me what i'm doing wrong..? ..and i can't use isotream.h

From just glancing over your code quickly I noticed you're missing a default for your switch. It doesn't seem like that would cause the error you're getting, but you should still fix it.

Can you copy the error exactly please?


Also - You never read in choice, so it's always going to be set to 1 since you set it on line 40.

X is also never initialized to anything.

Your error will more likely be something like: Unhandled exception, attempt to write to memory.

float amt;
printf(" enter the amount to withdraw: ");
scanf("%f", amt);

the scanf() is trying to write to *amt, which is bad. Try using scanf("%f", &amt) to pass the address of amt instead.

scanf always uses the syntax:

scanf("<format_specifier>",&<name_of_variable>);

You used the & operator.

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.