0% found this document useful (0 votes)
15 views

Assign 2.cpp

The document contains C++ code that reads in account information from the user, writes it to a text file, then reads it back in and performs calculations based on the account type and balances. It prompts the user to enter their account number, type (savings or current), minimum balance, and current balance, which it writes to a file. It then reads these values back in and outputs the account number and type, calculates interest or fees based on the type and balances, and displays the new balance.

Uploaded by

Zeeshan Rao
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views

Assign 2.cpp

The document contains C++ code that reads in account information from the user, writes it to a text file, then reads it back in and performs calculations based on the account type and balances. It prompts the user to enter their account number, type (savings or current), minimum balance, and current balance, which it writes to a file. It then reads these values back in and outputs the account number and type, calculates interest or fees based on the type and balances, and displays the new balance.

Uploaded by

Zeeshan Rao
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

#include <fstream>

#include <iostream>

using namespace std;

int main()
{
int account_number = 0;
cout << "ENTER YOUR ACCOUNT NUMBER" << endl;
cin >> account_number;
ofstream output;
output.open("test.txt");
output << account_number << " ";
char type = 'r';
cout << "ENTER YOUR ACCOUNT TYPE" << endl;
cin >> type;
output << type << " ";
double minimum = 0;
cout << "ENTER YOUR MINIMUM BALANCE " << endl;
cin >> minimum;
output << minimum << " ";
double balance = 0;
cout << "ENTER YOUR BALANCE " << endl;
cin >> balance;
output << balance << " ";
output.close();

ifstream input;
input.open("test.txt");
int s1 = 0;
char s2 = 'f';
double s3 = 0;
double s4 = 0;
if (input >> s1 >> s2 >> s3 >> s4) {
cout << "Account number is "<< s1 << endl;
if (s2 == 'c')
{
cout << "ACCOUNT TYPE " << "CURRENT" << endl;
}
if (s2 == 's')
{
cout << "ACCOUNT TYPE " << "SAVINGS" << endl;
}
}
else {
cout << "ERROR: Failed to read input file." << endl;
}
input.close();
double interest;
if (s2 == 's')
{
if (s3 > s4) {
s4 = s4 - 10;
cout << "YOU FAILED TO MEET THE MINIMUM BALANCE" << endl;
cout << "YOUR SERVICE CHARGES ARE " << " $ 10 " << endl;
cout << "CURRENT BALANCE " << s4 << endl;
}
if (s4 > s3)
{
interest = s4 * 0.04;
cout << "YOU RECIEVED INTEREST " << "$ " << interest << endl;
cout << "YOUR NEW BALANCE IS " << " $ " << s4 + interest << endl;
}
}
if (s2 == 'c')
{
if (s3 > s4)
{
s4 = s4 - 25;
cout << "YOU FAILED TO MEET THE MINIMUM BALANCE" << endl;
cout << "YOUR SERVICE CHARGES ARE " << " $ 10 " << endl;
cout << "CURRENT BALANCE " << s4 << endl;
}
if (s4 > s3)
{
if (s4 - s3 > 5000)
{
interest = 0.05 * s4;
cout << "YOU RECIEVED INTEREST " << "$ " << interest << endl;
cout << "YOUR NEW BALANCE IS " << " $ " << s4 + interest << endl;
}
if (s4 - s3 < 5000)
{
interest = 0.03 * s4;
cout << "YOU RECIEVED INTEREST " << "$ " << interest << endl;
cout << "YOUR NEW BALANCE IS " << " $ " << s4 + interest << endl;
}
}
}
return 0;
}

You might also like