Click here to Skip to main content
15,881,938 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
The program displays only an iteration its a atm project but nothing progress other than iteration kindly help. code is given below
#include<iostream>
#include<conio.h>
using namespace std;
void showmenu()
{
	cout<<"**********ATM INTERFACE**********"<<endl;
	cout<<" enter 1  to   checkbalance"<<endl;
	cout<<" enter 2  to   deposit"<<endl;
	cout<<" enter 3  to  withdraw"<<endl;
	cout<<":::::::::::::::::::::::::::::::::::::";
}
int main()
{
	int option;
	double balance=500;
	double deposit,withdraw;
	do{
	showmenu();
	cout<<"option";
	cin>>option;
    switch(option)
    {
    case1:cout<<"balance is"<<balance<<endl;
	break;
	case2:cout<<"  enter deposit amount";
	cin>>deposit;
	balance+=deposit;
	break;
	case3:cout<<"withdraw amount";
	cin>>withdraw;
if(withdraw<=balance)
{
balance-=withdraw;
}
else
{
	cout<<"insufficient amount";
	break;
}
}
	}while(option!=4);
	return 0;
	getch();
}


What I have tried:

I tried to correct it but I can't understand the logical error .please elaborate my logical error so that this can be corrected in the others pgms too
Posted
Updated 13-Apr-22 21:11pm
v5
Comments
Richard MacCutchan 9-Apr-22 12:24pm    
Please format your code properly with <pre> tags, and without all those extraneous ="" characters, so it is at least readable.
coderlearner 9-Apr-22 12:25pm    
Sorry I didn't get it
Richard MacCutchan 9-Apr-22 12:28pm    
Please use the Improve question link above, and format the code so it is clearly understandable by people who have not seen it before, and who do not know what your problem is.
coderlearner 9-Apr-22 13:03pm    
Sir hope this time my code is readable .on the top I've updated not the second one but the first one has been updated
Richard MacCutchan 9-Apr-22 12:44pm    
I have added the <pre> tags so it is partly readable. But you still have all those illegal characters in it. And given the number of syntax errors I do not understand how you are able to test it.

There is a while loop there:
C++
while(option!=4);
But it doesn't have a matching do statement. So it's not a do ... block of code ... while (condition) loop, it's a while (condition) ... block of code ... loop. And the semicolon on the end terminates it, so it sits there doing nothing waiting for a variable to magically change itself ... which will never happen.

To be honest, you would have spotted that for yourself if you'd spent 2 minutes with the debugger instead of 45 minutes waiting for others to fix it: Think of the development process as writing an email: compiling successfully means that you wrote the email in the right language - English, rather than German for example - not that the email contained the message you wanted to send.

So now you enter the second stage of development (in reality it's the fourth or fifth, but you'll come to the earlier stages later): Testing and Debugging.

Start by looking at what it does do, and how that differs from what you wanted. This is important, because it give you information as to why it's doing it. For example, if a program is intended to let the user enter a number and it doubles it and prints the answer, then if the input / output was like this:
Input   Expected output    Actual output
  1            2                 1
  2            4                 4
  3            6                 9
  4            8                16
Then it's fairly obvious that the problem is with the bit which doubles it - it's not adding itself to itself, or multiplying it by 2, it's multiplying it by itself and returning the square of the input.
So with that, you can look at the code and it's obvious that it's somewhere here:
C++
int Double(int value)
   {
   return value * value;
   }

Once you have an idea what might be going wrong, start using the debugger to find out why. Put a breakpoint on the first line of the method, and run your app. When it reaches the breakpoint, the debugger will stop, and hand control over to you. You can now run your code line-by-line (called "single stepping") and look at (or even change) variable contents as necessary (heck, you can even change the code and try again if you need to).
Think about what each line in the code should do before you execute it, and compare that to what it actually did when you use the "Step over" button to execute each line in turn. Did it do what you expect? If so, move on to the next line.
If not, why not? How does it differ?
Hopefully, that should help you locate which part of that code has a problem, and what the problem is.
This is a skill, and it's one which is well worth developing as it helps you in the real world as well as in development. And like all skills, it only improves by use!
 
Share this answer
 
Comments
Richard MacCutchan 9-Apr-22 12:47pm    
The do is on line 17, 5 below main. But given all the other syntax errors I doubt this is the code he has tried to run.
Richard MacCutchan 9-Apr-22 12:52pm    
Then do what I suggested above, use the Improve question link, correct the mistakes.
coderlearner 9-Apr-22 13:07pm    
Yes sir the question is improved as you said .hope the code is clear
If this is actually the current source code, then the compiler should note something like that.
Quote:
(line 40): warning C4060: switch statement contains neither "case" nor "default" designations

Please take a closer look at the case instructions...
 
Share this answer
 
Comments
coderlearner 9-Apr-22 21:30pm    
Sir kindly make some changes in the code so that it is easily understandable
merano99 13-Apr-22 11:16am    
Its your Code, so its up to you to learn that this does not what you want.
case1:cout<<"balance is"<
If you're interested in the program really to realize with C++ I suggest the following:

1. Avoid the conio.h file
C++
// #include<conio.h>

2. Replace the getch() function as it is not C++ and also deprecated.
C++
//getch();
std::cin.get();

3. It makes no sense to call other functions after a return.
The return (or exit) function should be used at the end or in case of an error.

4. In the current program, central objects are bank accounts. So it's close use a class for this.

5. Never save money as a float because the number format is not suitable for it.
In addition, invalid amounts and rounding errors can occur, which is undesirable for money.
C++
class account {   // bank account
public:
   account(long b): balance(b) { }
   int getbalance() { return balance; }
   void depositadd(long d) { balance += d; }
private:
   long balance;   // Amounts in cents e.g. 100*500
};

int getoption() {
   int option;
   do {
      showmenu();
      cout << "option: ";
      cin >> option;
   } while ((option < 1) || (option >4));
   return option;
}

int main()
{
   account acc(0);
   int option;
   do {
      option = getoption();
      switch( option )
      {
      case 1:
         cout << "balance is: " << acc.getbalance() << "\n";
         break;
      case 2:
         cout << "deposit in cent: ";
         long deposit;
         cin >> deposit;
         acc.depositadd(deposit);
...

   std::cin.get();
   return 0;
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900