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;
}

Recommended Answers

All 4 Replies

Remember this?
http://www.daniweb.com/forums/thread84431.html
Last edited by Ancient Dragon : 18 Hours Ago at 03:48. Reason: add code tags and disabled smiles in the text
Last edited by WaltP : 13 Hours Ago at 08:10. Reason: Added CODE tags -- you actually typed right over how to use them when you entered this post...
Last edited by WaltP : 13 Hours Ago at 08:17. Reason: Added CODE tags -- you typed right over instructions a third time!!!!

Or what about this one
http://www.daniweb.com/forums/thread84438.html
Last edited by WaltP : 13 Hours Ago at 08:01. Reason: Added CODE tags -- you actually typed right over how to use them when you entered this post...

Gee, way to go with the paying attention. People are not going to keep diapering you forever.

Not to mention, rubbish topic titles
http://www.catb.org/~esr/faqs/smart-questions.html#bespecific

>>I'm trying to write 2 codes in C++, but i'm having major problems
what exactly are the major problems ?

>>This is what i have so far:
That's nice. Now what do you want us to do? Or what question(s) do you have?

I wanted to know if someone can make suggestions or point out my mistakes. I can't get them to compile at all.

It will compile if you include <iostream>

line 31 of your first post is syntax error. you can't use for alone like that. maybe you meant an infinite loop like this: for (;;) line 38 is a do-nothing statement and may as well be deleted. Did you intend to call a function here?

line 47 of second program: remove the semicolon at the end of the line. This is a gottya for many (most) programmers, even old experienced ones.

line 63: variable month has not been previously initialized and contains some random value.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.