Oct 25, 2010 at 6:17pm UTC
This is a very simple program yet our professor is requiring the useage of functions and i believe this is where my error lays, but i can no figure it out. It is MENU driven and i think this is affecting my outcomes. Also im having problem with getting the total to come out to 0 and not a negative amount.
Here is my code. PLEASE HELP =)
______________________________________________________________________________
#include <iostream.h>
#include <cmath.h>
#include<iomanip>
#include<string.h>
void displaymainmenu(float &);
void getBASIC_INFO(float &,float &,float &); // P1
void displayBASIC_INFO(float,float,float, float&, float&, float&, int&);
void displaySummary_INFO(float,float,int);
void main ()
{
float princple;
princple=0;
system("cls");
displaymainmenu(princple);
return;
}
void displaymainmenu(float &princple)
{
int choice;
float payment;
float intrest;
float monthly_intrest;
float intrest_sum;
float reduction;
int payment_num;
cout<< " Main Loan Information Menu"<< endl;
cout<< " 1. Enter Loan Data "<< endl;
cout<< " 2. Payment schedule "<< endl;
cout<<" 3. Summary Data "<< endl;
cout<< " 4. Exit "<<endl;
cin>>choice;
if ( choice == 1)
getBASIC_INFO(princple,intrest,payment); //C1
if (choice == 2)
displayBASIC_INFO(princple, payment,intrest,monthly_intrest,intrest_sum,reduction,payment_num);//C2
if(princple == 0)
{
cout<< "Invalid Choice-Please enter loan data"<<endl;
system("pause");
displaymainmenu(princple);
}
if (choice == 3)
displaySummary_INFO(princple,intrest_sum,payment_num);
if(princple == 0)
{
cout<< "Invalid Choice-Please enter loan data"<<endl;
system("pause");
displaymainmenu(princple);
}
if (choice == 4)
exit(0);
if (choice <4)
cout<<"Invalid Choice-Please enter 1-4"<<endl;
return;
}
void getBASIC_INFO(float &princple, float &intrest, float &payment) //F1
{
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.setf(ios::fixed);// ?
cout<<"Please enter loan amount-"<<endl;
cin >>princple;
cout<<"$"<<setprecision(2)<<princple<<endl;
if ( princple >= 9999999999)
{
cout<< "Loan is too large"<<endl;
system("pause");
displaymainmenu(princple);
}
cout<<" Please enter annual interest rate-"<<endl;
cin >> intrest;
if (intrest< 1)
cout<<" Please display Intrest in whole number - Example 9.5 percent"<<endl;
cout<<"Please enter payment amount-"<<endl;
cin>>payment;
cout<<"$"<<setprecision(2)<<payment<<endl;
if(princple <= payment)
{
cout <<" Invalid Information - Payment can not be larger than loan"<< endl;
system("pause");
displaymainmenu(princple);
}
system("pause");
displaymainmenu(princple);
}
void displayBASIC_INFO(float princple, float payment, float intrest,float &monthly_intrest,float &intrest_sum,float &reduction,int &payment_num) //F2
{
payment_num = 0;
cout<< "Payment Number--Princple Total---Intrest Due--Payment--Reduction-- New Princple Total"<<endl;
while ( princple >= payment)
{
payment_num++;
monthly_intrest = ( intrest/12) * .1;
intrest_sum= princple * monthly_intrest - princple;
reduction =payment-intrest_sum ;
princple = princple + intrest_sum - payment;
if (intrest_sum == payment)
cout << "Payment must be larger than Intrest Sum per payment"<<endl;
if (payment_num % 10== 0)
{
cout<< "Payment Number--Princple Total---Intrest Due--Payment--Reduction-- New Princple Total"<<endl;
system("pause");
}
//Display
cout<<setw(5)<< payment_num<< ".)";
cout<<setw(10)<<setprecision(2)<<princple;
cout<<setw(6)<< setprecision (2)<< intrest_sum;
cout<<setw(7)<< setprecision(2)<<payment;
cout<<setw(5)<< setprecision(2)<< reduction;
cout<<setw(10)<< setprecision(2)<<princple<<endl;
}
if (princple < payment)
{
payment_num= payment_num + 1;
payment = princple;
monthly_intrest = ( intrest/12) * .1;
intrest_sum= princple * monthly_intrest - payment;
reduction = intrest_sum - payment;
princple = princple + intrest_sum - payment;
cout<<setw(5)<< payment_num<< ".)";
cout<<setw(10)<<setprecision(2)<<princple;
cout<<setw(6)<< setprecision (2)<< intrest_sum;
cout<<setw(7)<< setprecision(2)<<payment;
cout<<setw(5)<< setprecision(2)<< reduction;
cout<<setw(10)<< setprecision(2)<<princple<<endl;
}
system ("pause");
system("cls");
displaymainmenu(princple);
}
void displaySummary_INFO(float princple,float intrest_sum,int payment_num)//F3
{
cout << "Initial Loan -$"<< princple<< endl;
cout<<" Amount paid in Intrest - $"<<intrest_sum<<endl;
cout<<" Number of monthly Payments-"<<payment_num<<endl;
system("pause");
system("cls");
displaymainmenu(princple);
}
Oct 25, 2010 at 6:20pm UTC
Please edit your post and put code tags around the source code.