Can someone please help me with these 2 problems.
Here is number 1.
I have to write a family of overloaded functions called equal(), which take two arguments of the same type, returning 1 if the arguments are equal, and 0 otherwise. This is what i have that refuses to compile.

#include <cstrings>
using std::cin;
using std::cout;
using std::endl;

int equal(int a,int b)
{
   return (a,b) ? 1 : 0;
}

int equal(double a,double b)
{
   return (a,b) ? 1 : 0;
}

   equal(char a,char b)
{
   return (a==b) ? 1 : 0;
}

int equal(char* a,char* b)
{
   return strcmp(a,b)==0 ? 1 : 0;
}

int main()
{
   int iA=3, iB=5;
   cout << "Comparing iA = " << iA << " and iB = " << iB << endl;
   if (equal(iA,iB))
      cout << "iA and iB are the same" << endl;
   else
      cout << "iA and iB are different" << endl;

   double dA=3.5, dB=3.5;
   cout << "Comparing dA = " << dA << " and dB = " << dB << endl;
   if (equal(dA,dB))
      cout << "dA and dB are the same" << endl;
   else
      cout << "dA and dB are different" << endl;

   char* pA = "greeting";
   char* pB = "to you";
   cout << "Comparing pA = \"" << pA << "\" and pB = \"" << pB << "\"" << endl;
   if (equal(pA,pB))
      cout << "pA and pB are the same" << endl;
   else
      cout << "pA and pB are different" << endl;

   char* pC = "mickey";
   cout << "Comparing pB = \"" << pB << "\" and pC = \"" << pC << "\"" << endl;
   if (equal(pB,pC))
      cout << "pB and pC are the same" << endl;
   else
      cout << "pB and pC are different" << endl;

   return 0;
}

----------------------------------------------------------------------------------Here is number 2.

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 what i ahve so far, i don't know if this is close to being right.

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

I hate sounding hopeless but i really need someone that knows c++ to help me.

Ancient Dragon commented: learn to use code tags correctly in ALL posts. -4

Recommended Answers

All 2 Replies

Are you blind, senile, have demeinita, or maybe older than I am? I have already told you TWICE what the problem is with that second program. And this is the third time you have posted that same code. Now, go back and re-read the responses to your previous threads. I'm going to put you on my ignore list if you don't start reading the responses to your other threads. I would hate to see you get banned just because you fail to read (a few more screw-ups away from it.)

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.