my problem is, when i try to withdraw bigger than balance...it will display the remaining balance..it display negative..which is wrong..instead of display the msg "you have not enough money".

what's wrong with my code?

this is my code:::::
    if (withdraw == 1)
				  {
				    bal=bal-100;
				    gotoxy(25,17);
				    cout<<"Your balance now is Php "<<bal;
				  }
				  if (withdraw == 2)
				  {
				    bal=bal-500;
				    gotoxy(25,17);
				    cout<<"Your balance now is Php "<<bal;
				  }
				  if (withdraw == 3)
				  {
				    bal=bal-1000;
				    gotoxy(25,17);
				    cout<<"Your balance now is Php "<<bal;
				  }
				  if (withdraw == 4)
				  {
				    bal=bal-2500;
				    gotoxy(25,17);
				    cout<<"Your balance now is Php "<<bal;
				  }
				  if (withdraw == 5)
				  {
				    bal=bal-5000;
				    gotoxy(25,17);
				    cout<<"Your balance now is Php "<<bal;
				  }
				  if (withdraw == 6)
				  {
				    bal=bal-10000;
				    gotoxy(25,17);
				    cout<<"Your balance now is Php "<<bal;
				  }
				  if (withdraw == 0)
				  {
				    gotoxy(25,15);
				    cout<<"Enter amount:";
				    gotoxy(39,15);
				    cin>>withdraw;
				    bal=bal-withdraw;
				    gotoxy(25,17);
				    cout<<"Your balance now is Php "<<bal;

				  }

			     else if (withdraw > bal)
				  {
				    gotoxy(24,16);
				    cout<<"The money you input is not enough.";

				  }

you should probably use a switch statement instead of a series of if statements, unless your assignment requires if statements. Move the last statement (lines 50-54) to the beginning so that its tested first, then put else statements before each if statement, like you did on line 50.

Member Avatar for GreenDay2001

Use [ code ] tags while posting source code.

I couldn't know with this bunch of code that what are you doing. First you check withdraw using if for every case(not even using else if) and then ask for withdraw and then again check after you subtract and show balance.

Although you whole code seems wrong, but I think you it could be something else what I think since its just a part, but problem is you subract and show balance before checking whether withdraw is greater than balance or not.

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.