Difficulty with if statements

So, I haven't used C++ in a while and I want to get back into it and learn more.
I wrote a simple program to set up the balance of a bank account, and then withdraw an amount and display the final balance, then close.
Now I took this program, and added the option of a second transaction, It ignores whether the strings are Y or N and goes through the entire program.

Anyone care to help?

#include <iostream>
#include <stdlib.h>
#include <string>
using namespace std;

int main()
{
float balance;
int x;
string y;
cout << "What is your balance? \n";
cin >> balance;
cout << "How much do you wish to withdraw? \n";
cin >> x;
balance = balance - x;
cout << "Your new balance is ";
cout << balance;
cout << "\n";
cout << "Do you wish to complete another transaction? (Y or N) \n";
cin >> y;
if (y == "Y");
{
string b;
cout << "Do you wish to deposit this time? (Y or N) \n";
cin >> b;
if (b == "N");
{
cout << "How much do you wish to withdraw?\n";
cin >> x;
balance = balance - x;
cout << "Your new balance is";
cout << balance;
}
if (b == "Y");
{
cout << "How much do you wish to deposit?\n";
cin >> x;
cout << "\n Your new balance is \n";
cout << balance;
system("pause");
return(0);
}
}
if (y == "N");
{


system("pause");
return(0);
}
}
please remove semocolon after each if condition...
that's the only problem in your code..
Use char in place of string if possible..
Last edited on
It is true that you might as well use chars for this situation, but strings will still work.

The problem is you shouldn't have semicolons at the end of your if statements. Remove those and it will work correctly
Thank you all, Fixed the issue :D
Topic archived. No new replies allowed.