Need help fixing "Loop" C++

Code help, language discussions, and software development advice.
Post Reply
zerohero
Registered User
Posts: 1
Joined: February 22nd, 2005, 2:20 am

Need help fixing "Loop" C++

Post by zerohero »

#include <iostream> #include <fstream> using namespace std; int main() { int age, mdep; float iinv, ebal, rate, intrst, yearlyRate; ofstream oFile("out.txt"); if (!oFile) { cout << "Error in opening file."; cin.get(); return(-1); } cout << "Age (Less than 65): "; oFile << "Age (Less than 65): "; cin >> age; oFile << age; cout << "\nInitial Investment: "; oFile << "\nInitial Investment: "; cin >> iinv; oFile << iinv; cout << "\n30-Day Deposit: "; oFile << "\n30-Day Deposit: "; cin >> mdep; oFile << mdep; cout << "\nInterest Percent: "; oFile << "\nInterest Percent: "; cin >> rate; oFile << rate; cout << "\nPress Return to continue."; cin.ignore(80, '\n'); cin.get(); cout << "\n==============================================================================="; cout << "\nFuture Value Calculation"; cout << "\nStarting Age: " << age; cout << "\nStarting Investment: " << iinv; cout << "\n30-Day Deposit: " << mdep; cout << "\nInterest Rate: " << rate << "%"; cout << "\n==============================================================================="; oFile << "\n\n==============================================================================="; oFile << "\nFuture Value Calculation"; oFile << "\nStarting Age: " << age; oFile << "\nStarting Investment: " << iinv; oFile << "\n30-Day Deposit: " << mdep; oFile << "\nInterest Rate: " << rate << "%"; oFile << "\n==============================================================================="; cout << "\nPress Return to continue."; cin.get(); ebal = iinv; cout << "\nAge\tBBal\t\tInt\t\tDep\tEBal"; cout << "\n-----------------------------------------------------\n"; oFile << "\n\nAge\tBeg Bal\t\tInterest\t\tDeposits\tEnd Bal"; oFile << "\n-----------------------------------------------------\n"; int days = 0; for (int x = age; x <= 65; x++) { while (days < 365) { iinv = ebal; float yearlyRate = (yearlyRate / 100); intrst = (yearlyRate / 365); ebal = (iinv + intrst); if (days%30 == 0) { ebal = (ebal + mdep); } if (days == 364) { days = 0; break; } days++; } cout << "\n" << ebal << "\n"; oFile << "\n" << ebal << "\n"; age = (age + 1); cout << age << "\t" << iinv << "\t\t" << intrst << "\t\t" << mdep << "\t" << ebal << "\n"; oFile << age << "\t" << iinv << "\t\t" << intrst << "\t\t" << mdep << "\t" << ebal << "\n"; } oFile.close(); cin.get(); return(0); }
Post Reply