Can someone help im suppose 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 <cstring>
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;
}

.......................................................................................................
Can someone please tell me why this one will not compile also, any help will be greatly appreciated. Here is my assignment for this one.
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 "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;
}

Can someone help im suppose 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.

What question(s) do you have about the code you posed? People normally don't post code just for the hell of it.

Can someone please tell me why this one will not compile

I already did -- here.

No offense, eyedea2011, but the syntax you're using is either really old or really new, because a lot of it doesn't make much sense to me. Why not just use

if(a==b){
    return true;
} else {
    return false;
}

Just an idea...

Posting the errors your get when you try to compile the code would help.

// A tip: you don't need to write 
using std::cin;
using std::cout;

// If you have..
using namespace std;

// Because std::cin and std::cout are all part of the std namespace, so that one line should suffice.

Posting the errors your get when you try to compile the code would help.

// A tip: you don't need to write 
using std::cin;
using std::cout;

// If you have..
using namespace std;

// Because std::cin and std::cout are all part of the std namespace, so that one line should suffice.

You also don't need to bring the entire std namespace into scope, so just specifying std::cin and std::cout is a far better idea.

in the comparison program, the first two prototypes are incorrect. You have the test condition (a,b) which makes no sense. Later on you use it correctly with (a==b).

If you took the time to read the compiler errors, you could have noticed this immediately !

I learn allot from compiler puke...

Comments
compiler puke :)
This article has been dead for over six months. Start a new discussion instead.