I'm trying to write 2 codes in C++, but i'm having major problems. The first one should output something like this:
Enter a number: 123 -- Enter a name: Jack
Thank you, Your name and number is Jack and 123.
#include "stdafx.h"
#include <iomanip>
using std::cin;
using std::cout;
using std::endl;
// Read a number and a name
void GetData(int& number, char name[])
{
cout << "Enter a number: ";
cin >> number;
if (number != 0)
{
cout << endl << "And a name: ";
cin >> name;
}
}
void PutData(int number, char name[])
{
cout << endl << "Thank you. Your name and number are "
<< number << " and \"" << name << "\"" << endl;
}
int main()
{
int (number);
char name[15];
for
{
GetData(number, name);
if (number == 0)
break;
(number, name);
}
return 0;
}
.......................................................................................................
This is the second code.
Write the program as a procedural C++ program. Allow the user to input the amount of a mortgage and then select from a menu of mortgage loans:
- 7 year at 5.35%
- 15 year at 5.5%
- 30 year at 5.75%
Use an array for the different loans. Display the mortgage payment amount. Then, list the loan balance and interest paid for each payment over the term of the loan. On longer-term loans, the list will scroll off the screen. Do not allow the list to scroll off the screen, but rather display a partial list and then allow the user to continue the list. Allow the user to loop back and enter new data or quit. Insert comments in the program to document the program
This is what i have so far:
#include "stdafx.h"
#include <iostream>
#include <cmath>
#include <iomanip>
using std::cin;
using std::cout;
using namespace std;
int main()
{
const int MONTHS = 12;
double loan, rate, balance, payment;
double month;
double interest;
double principal;
double monthlypayment;
cout << "Loan amount:$"; //Loan amouny
cin >> loan;
cout << "Annual Interest rate:"; //Loan amount
cin >> rate;
cout << "Monthly payment:"; //Monthly payment
cin >> payment;
cout << endl;
cout << setw(5) << "Month"; //Display moth
cout << setw(10) << "Interest"; //Dispaly interest
cout << setw(10) << "principal"; //Display principal
cout << setw(10) << "Monthly payment"; //Display payment
cin >> payment;
cout << endl;
cout << setw(5) << "Month";
cout << setw(10) << "Interest";
cout << setw(10) << "Principal";
cout << setw(10) << "Balance" << endl;
cout << "..............................\n";
balance = loan;
double numPayments = loan - payment;
for (int x = 1; x <= numPayments; x++);
{
double interest, principal;
interest = rate / MONTHS * balance;
if (x !=numPayments)
{
principal = payment - interest;
}
else
{
principal = balance;
payment = balance + interest;
}
double balance = principal;
cout << setw(4) << month;
cout << setw(10) << interest;
cout << setw(10) << principal;
cout << setw(10) << balance << endl;
}
return 0;
}