In: Computer Science
hello!! So this is my CIS assignment, my professor is very hard to understand and he expects us to be perfect lol. I have tried to run this problem with a code but as you can see he wants to see that when the program is ran, all of the outcomes are listed all at once, the code that I have does meet the math part when it comes to the answers but as I said it does not show me all of my answers listed if not I have to put all of the inputs. also professor wants to see two different outcomes for example
income balance=-100
he wants to see income=nnnn
number of checks
bank fee=nnnn
in other words he wants to see me putting the income but he wants to see an additional.... (as part of the outcome)
I am really sorry but I have tried to go to tutoring and the time for me does not work......
A bank charges $10 per month plus the following check fees for a commercial checking account: $0.10 each for fewer than 20 checks $0.08 each for 20-39 checks $0.06 each for 40-59 checks $0.04 each for 60 or more checks The bank also charges an extra $15.00 if the balance of the account falls below $400 (before any check fees are applied). Write a program that asks for the beginning balance and the number of check written. Compute and display the bank's service fees for the month. Input Validation: Do not accept a negative value for the number of checks written. If a negative value is given for the beginning balance, display an urgent message indicating the account is overdrawn. The transaction data file: transaction.txtPreview the documentPreview the document Output: Beginning balance: $-100 Number of checks written: 30 Your account is overdrawn! The bank fee this month is $27.40 Beginning balance: $400.00 Number of checks written: -20 Number of checks must be zero or more. Beginning balance: $300.00 Number of checks written: 36 The bank fee this month is $27.88 Beginning balance: $300.00 Number of checks written: 47 The bank fee this month is $27.82 Beginning balance: $350.00 Number of checks written: 5 The bank fee this month is $25.50 Beginning balance: $300.00 Number of checks written: 70 The bank fee this month is $27.80
Reading data from a file
# include <iostream>
# include <iomanip>
# include <fstream>
using namespace std;
std; int main()
{ ifstream input;
input.open("transaction.txt");
while (input>>balance>>check)//while loop
{
//Processing the checks }
}//end while loop
/////////// he also provided with this, to include in the program.
thanks! for the help I really appreciate it
few days ago I got this answer:
//Please like and comment
//code.cpp
# include <iostream>
# include <iomanip>
# include <fstream>
using namespace std;
int computeCharge(int balance)
{
int charge = 10;
if (balance < 400)
{
charge += 15;
}
return charge;
}
float computCheckFee(int numberOfChecks)
{
if (numberOfChecks < 20)
{
return numberOfChecks * 0.10;
}
else if (numberOfChecks >= 20 && numberOfChecks < 40)
{
return numberOfChecks * 0.08;
}
else if (numberOfChecks >= 40 && numberOfChecks < 60)
{
return numberOfChecks * 0.06;
}
else
{
return numberOfChecks * 0.04;
}
}
float computeFee(int balance, int numberOfChecks)
{
return computCheckFee(numberOfChecks) + computeCharge(balance);
}
void getResult(int balance, int checks)
{
if (checks < 0)
{
cout << " Number of checks must be zero or more" <<endl;
}
else if (balance < 0)
{
cout << " Your account is overdrawn! The bank fee this month is $" << computeFee(balance,checks)<< endl;;
}
else
{
cout << " The bank fee this month is $" << computeFee(balance, checks) << endl;
}
}
int main()
{
ifstream input;
input.open("transaction.txt");
int balance = 0, check = 0;
while (input >> balance >> check)//while loop
{
cout << "Beginning balance : $" << balance << " Number of checks written: " << check;
getResult(balance, check);
}//end while loop
return 0;
}
//output
but when I run the program if you take a look at it it has "float computeFee(int balance, int numberOfChecks)" this part seems to be the problem because when I run the problem it says the variables are not declared. pls I need help!
#include <iostream>
# include <iomanip>
# include <fstream>
using namespace std;
// change the data type of balance to float in every function parameter ( since balance may be in decimal)
int computeCharge(float balance)
{
int charge = 10;
if (balance < 400)
{
charge += 15;
}
return charge;
}
float computCheckFee(int numberOfChecks)
{
if (numberOfChecks < 20)
{
return numberOfChecks * 0.10;
}
else if (numberOfChecks >= 20 && numberOfChecks < 40)
{
return numberOfChecks * 0.08;
}
else if (numberOfChecks >= 40 && numberOfChecks < 60)
{
return numberOfChecks * 0.06;
}
else
{
return numberOfChecks * 0.04;
}
}
float computeFee(float balance, int numberOfChecks)
{
return computCheckFee(numberOfChecks) + computeCharge(balance);
}
void getResult(float balance, int checks)
{
if (checks < 0)
{
cout << " Number of checks must be zero or more" <<endl;
}
else if (balance < 0)
{
cout << " Your account is overdrawn! The bank fee this month is $" << computeFee(balance,checks)<< endl;;
}
else
{
cout << " The bank fee this month is $" << computeFee(balance, checks) << endl;
}
}
int main() {
ifstream input;
input.open("transaction.txt"); // provide full path to file
float balance = 0; //make balance float as balance may be in decimal
int check = 0;
cout<<fixed<<setprecision(2);
while (input >> balance >> check)//while loop
{
cout << "Beginning balance : $" << balance << " Number of checks written: " << check;
getResult(balance, check);
}//end while loop
return 0;
}
//end of program
Output:
Input file:
The format of file is:
<beginning_balance><space><number_of_checks>
Each line consists of beginning_balance and number_of_checks separated by a space
Output: