Question
I need someone to help me correct these last few errors in code. The outputs for files 1 and 6 at the bottom of the
I need someone to help me correct these last few errors in code. The outputs for files 1 and 6 at the bottom of the code give me a double output for the last set of numbers. someone please help me fix this and explain what in the code is wrong
First i will post the code, then the answers i get for the outputs.
#include
double calculateFutureValue(double presentValue, double interestRate, int months){ double futureValue = (double)presentValue * pow( (1 + interestRate), months); return futureValue;}
unsigned int readfile(ifstream& inF, double& presentValue, double& interestRate, int& months){ inF >> presentValue; inF >> interestRate; inF >> months; if(presentValue <= 0 || interestRate <= 0 || months <= 0){ return 2;} else if( !(presentValue <= 0 || interestRate <= 0 || months <= 0)) return 1;
if(inF.eof()) return 0; }
void write2File(ofstream &of, double futureValue, double presentValue, double interestRate, int months) { of << futureValue << "\t" << presentValue << "\t" << interestRate << "\t" << months << " "; } // main function int main(void) { string infile; cin >> infile; ifstream inF; inF.open(infile.c_str()); if(!inF) { cout << "File \"" << infile << "\" could not be opened" < if(returnVal == 2){ cout << setprecision(2) << fixed << showpoint; cout << presentValue << " " << interestRate << " " << months << endl; cout << "One or more of the above values are not greater than zero" << endl; if (presentValue == 0 && interestRate == 0 && months == 0){ return(0); } } else if(returnVal == 1) { futureValue = calculateFutureValue(presentValue, interestRate/100, months); write2File(of, futureValue, presentValue, interestRate, months); } } inF.close(); of.close(); return (0); } NUMBERS 1 AND 6 HAVE THE LAST OUTPUT PRINTED TWICE THIS IS WHAT I NEED HELP WITH. 1: Compare output keyboard_arrow_up 0 / 10 Input input2.txt Your output Future Value Present Value Monthly Interest Months 12205.06 10000.00 0.42 48 12205.06 10000.00 0.42 48 (double output here as well) Expected output Future Value Present Value Monthly Interest Months 12205.06 10000.00 0.42 48 2: Compare output keyboard_arrow_up 10 / 10 Input input3.txt Your output -10000.00 1.10 48 One or more of the above values are not greater than zero 10000.00 -1.00 12 One or more of the above values are not greater than zero 10000.00 1.10 0 One or more of the above values are not greater than zero 0.00 0.00 0 One or more of the above values are not greater than zero 3: Unit test keyboard_arrow_up 5 / 5 Call to calculateFutureValue # 1 Test feedback The call to calculateFutureValue returned the correct value 4: Unit test keyboard_arrow_up 5 / 5 Call to calculateFutureValue # 2 Test feedback The call to calculateFutureValue returned the correct value 5: Unit test keyboard_arrow_up 5 / 5 Call to calculateFutureValue # 3 Test feedback The call to calculateFutureValue returned the correct value 6: Compare output keyboard_arrow_up 0 / 10 Input input4.txt (wrong output plese help to fix double output at end. Your output Future Value Present Value Monthly Interest Months 5458.19 3000.00 0.50 120 35.95 1.00 1.00 360 76079.56 45000.00 1.10 48 76079.56 45000.00 1.10 48 (this double output is what messes up the code Expected output Future Value Present Value Monthly Interest Months 5458.19 3000.00 0.50 120 35.95 1.00 1.00 360 76079.56 45000.00 1.10 48 7: Compare output keyboard_arrow_up 5 / 5 Input invalidfile.txt Your output File "invalidfile.txt" could not be opened 8: Compare output keyboard_arrow_up 0 / 1 (wrong output) Input input1.txt Your output 0.00 0.00 -595202056 One or more of the above values are not greater than zero Expected output This test case should produce no output 9: Compare output keyboard_arrow_up 4 / 4 Input input1.txt Your output Future Value Present Value Monthly Interest Months
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started