I cna\'t run this code. what is incorrect? #include \"stdafx.h\" #include <iostr
ID: 3711860 • Letter: I
Question
I cna't run this code.
what is incorrect?
#include "stdafx.h"
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
long balance;
ofstream outfile;
ifstream infile;
int choice;
int number = 1;
cout << "1. Crete an account" << endl;
cout << "2. Deposit" << endl;
cout << "3. Withdraw" << endl;
cout << "Enter 1, 2, 3";
cin >> choice;
switch (choice)
{
case '1' :
cout << "Your account number is " << number << endl;
cout << "How much would you like to use to open your account" << endl;
cin >> balance;
outfile.open("C:\Users\***\Documents\Bank Acount.txt");
outfile << balance;
outfile.close();
case '2' :
long deposit = 0;
cout << "Enter your account number?";
cin >> number;
if (number != 1)
{
cout << "You entered the wrong accnt number or you need to create a new account" << endl;
}
cout << "Enter the amount you want to deposit?" << endl;
cin >> deposit;
balance += deposit;
infile.open("C:\Users\***\Documents\Bank Acount.txt");
infile >> balance;
if (!infile)
{
cout << "File open failure!";
}
infile.close();
case'3':
long depoist;
long with = 0;
cout << "Enter your account number?";
cin >> number;
if (number != 1)
{
cout << "You entered the wrong account number or you need to crete a new account" << endl;
}
cout << "Enter the amount you want to withdraw?" << endl;
cin >> with;
balance -= with;
infile.open("C:\Users\***\Documents\Bank Acount.txt");
infile >> balance;
if (!infile)
{
cout << "File open failure!";
}
infile.close();
}
return 0;
}
Explanation / Answer
The error is fixed now:
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
long balance,deposit =0,with=0;
ofstream outfile;
ifstream infile;
int choice;
int number = 1;
cout << "1. Crete an account" << endl;
cout << "2. Deposit" << endl;
cout << "3. Withdraw" << endl;
cout << "Enter 1, 2, 3";
cin >> choice;
switch (choice)
{
case 1:
cout << "Your account number is " << number << endl;
cout << "How much would you like to use to open your account" << endl;
cin >> balance;
outfile.open("C:\Users\***\Documents\Bank Acount.txt");
outfile << balance;
outfile.close();
break;
case 2:
deposit = 0;
cout << "Enter your account number?";
cin >> number;
if (number != 1)
{
cout << "You entered the wrong accnt number or you need to create a new account" << endl;
}
cout << "Enter the amount you want to deposit?" << endl;
cin >> deposit;
balance += deposit;
infile.open("C:\Users\***\Documents\Bank Acount.txt");
infile >> balance;
if (!infile)
{
cout << "File open failure!";
}
infile.close();
break;
case 3:
deposit=0;
with = 0;
cout << "Enter your account number?";
cin >> number;
if (number != 1)
{
cout << "You entered the wrong account number or you need to crete a new account" << endl;
}
cout << "Enter the amount you want to withdraw?" << endl;
cin >> with;
balance -= with;
infile.open("C:\Users\***\Documents\Bank Acount.txt");
infile >> balance;
if (!infile)
{
cout << "File open failure!";
}
infile.close();
break;
default:
break;
}
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.