Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 308
  • Last Modified:

object-oriented C++ program

I can't get my prgram to quit or enter new value
#include <iomanip>
#include <cstdlib>
#include <iostream>
#include <string>
#include <sstream>
#include <cmath>
#include <time.h> 
 
 
using namespace std;
 
 
using std::cout;
using std::endl;
using std::cin;
  
class Mortgage                         //class is defined
 
{
 
public:                              // public access
void header(); 
void enterprinc(); 
 
 
double princ;                        //principle of the loan
double anInt;                       //Interest of the loan
int yrs;                               //Term of the loan
};
 
                     //All the functions within the class 
 
 
void Mortgage::header()                        // header of the program.
{
 
cout << "steve world \n\n";
cout << endl;
cout << "Write the program as an object-oriented C++ program that allows the user to select which way they want to calculate a mortgage:\n\n";
cout << endl;
 
}
 
void Mortgage::enterprinc ()
{
cout << endl;
cout << "Enter the amount for the Loan:$"; //User enters amount for the Loan
cin >> princ;
 
}
 
int main ()
 
{
 
while (1) { 
 
Mortgage mortgageTotal;
 
double princ = 0;                             //*Principle amount of loan is entered by user
double annualIntRate []= {5.35, 5.5, 5.75,};         //*Annual interest rate choosen in scenario 
double yrs []= {7, 15, 30,};                 //*Term of the loan is choosen with scenario
double EMI = 0;                                  //*Monthly Payment
double intPd;                                    //*Interest Paid
double bal;                                      //*Loan Balance
double amtPd;                                   //*Amount Paid on Loan
 
int NumOfPay;                                  //*Number of Payments
int Mnth;                                  //*Allows loop for loan balance and interest paid
int SL = 0;                                     //*Scroll List for loan balance and interest paid
char indicator;     //User chooses to enter Int and term or select scenario
 
 
//Begin Loop
 
{
mortgageTotal.header ();
mortgageTotal.enterprinc ();
 
//I added time and date and allow the enduser put his or her name in the program.
    
        time_t rawtime;
        struct tm * timeinfo;
 
        time ( &rawtime );
        timeinfo = localtime ( &rawtime );
        printf ( "Current local time and date: %s", asctime (timeinfo) );
 
        
  char question[] = "Please, enter your first name: ";
  char greeting[] = "Hello, ";
  char yourname [100];
  cout << question;
  cin >> yourname;
  cout << greeting << yourname << "!";
  cout<<endl;
 
 
 
 
 
 
cout<< "Would you like to select a scenario or enter your choice?"<< endl;
cout<< "Press S to select your scenario, or T to enter your choices"<<endl;
cin >> indicator;
 
if (indicator == 'S','s')
{
 
cout << "Please select your Terms and Rates from the following choices: " << endl;
cout << "1. 7 years at 5.35%" << endl;
cout << "2. 15 years at 5.5%" << endl;
cout << "3. 30 years at 5.75%" << endl;
cout << endl;
cout << " your selection:";
 
int select;
cin >> select;
cout << endl << endl << endl;
 
switch (select)
{
 
case 0: cout << endl; 
break;
 
 
case 1:
yrs[0] = 7;
annualIntRate[0] = 5.35; 
cout << "You have selected 7 Years and 5.35%" << endl; 
 EMI = (mortgageTotal.princ*((annualIntRate[0]/1200)/(1 - pow((1+(annualIntRate[0]/1200)),-1*(yrs[0]*12)))));
break;
 
case 2: 
yrs[1] = 15;
annualIntRate[1]= 5.50; 
cout << "You have selected 15 Years at 5.50%" << endl; 
 EMI = (mortgageTotal.princ*((annualIntRate[1]/1200)/(1 - pow((1+(annualIntRate[1]/1200)),-1*(yrs[1]*12)))));
break;
 
case 3: 
yrs[2] = 30;
annualIntRate[2] = 5.75; 
cout << "You have selected 30 Years at 5.75%" << endl; 
 EMI = (mortgageTotal.princ*((annualIntRate[2]/1200)/(1 - pow((1+(annualIntRate[2]/1200)),-1*(yrs[2]*12)))));
break;
 
default: 
cout << "Invalid Line Number" << endl;
if ((select < 1)|| (select > 3))
 
{ 
system("cls");
cout << "Please enter a cool choice!!!";
system("PAUSE");
 
system("cls");
return main();
}
}
}
 
 
cout << " the amount you have entered is: \n";
cout << endl;
cout << "Your Monthly Payment is: $" << EMI << "\n";
cout << endl;
 
// Formulas for Number of Payments, 
double NunOfPay = yrs [0] * 12;
SL = 0;
 
for (Mnth = 1; Mnth <= NunOfPay; ++Mnth)
{
 
//Formula
intPd = mortgageTotal.princ * (annualIntRate[0] / 1200);
amtPd = EMI - intPd;
bal = mortgageTotal.princ - amtPd;
if (bal < 0)bal = 0;
mortgageTotal.princ = bal;
 
// Scroll List titles to seperate the loan balance and Interest paid
 
if (SL == 0)
 
{
cout << "Balance of Loan" << "\t\t\tAmount of Interest Paid" << endl;
}
 
cout << setprecision(2) << fixed << "$" << setw(5) << bal << "\t\t\t\t$"<< setw(5) << intPd << endl;
++SL;
 
 
 
if (SL == 6)
 
{
cout << "Would you like to keep going and see the rest of the information or Quit?\n";
cout << endl;
cout << "Enter 'R' to see the remainder, Enter 'C' to try another example, Enter 'D' for done.\n";
cin >> indicator;
 
                       
 
if 
 
(indicator == 'R'||indicator == 'r')SL = 0;
 
else
 
if
 
(indicator == 'C'||indicator == 'c')
break;
 
 
else
if
(indicator == 'D'||indicator == 'd')
cout << endl;
 
}
 
}
 
}
 
while ((indicator!='C')&&(indicator!='c')); 
 
//Exit the program 
 
 
   char choice;
   cout << "Enter 'Q' to quit, anything else to start over" << endl;
 
   cin >> choice;
 
   if (choice == 'q' || choice == 'Q') break; // exit loop
 
   } // <--- end of 'while' from above
   return 0;
      }

Open in new window

0
imagekrazy
Asked:
imagekrazy
1 Solution
 
Infinity08Commented:
Most of the comments I made here :

        http://www.experts-exchange.com/Programming/Languages/CPP/Q_24118177.html

are still valid.

You should really fix those first before continuing.
0
 
imagekrazyAuthor Commented:
okay thanks
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now