for lines 14, 15 and 16 the error is that I have undeclared identifiers for a, b and c.
Does anyone know how to fix this?
thanks for your help.

#include <cmath>
#include <iostream>
#include <string>
using namespace std;

bool die(const string & msg);
bool getDouble(double a, const string & b)	;
double squarePerimeter(double a);
double squareArea(double a);

int main(){


cout << getDouble(a, "Enter length of side");
cout << squarePerimeter(b)   ;
cout << squareArea(c)	   ;

return 0;
}

bool die(const string & msg){
	cout << msg << endl;
	exit(EXIT_FAILURE);	 
}

bool getDouble(double & a, const string & b){
	
	cout << b;
	if(cin>>a)
	return true;
	else 
	return false;
}

	
double squarePerimeter(double & a){
	double b;
	b = 4*a;
	if (a<0)
		bool die("side is negative");
	else 
	cout << "The perimeter of the square is " << b << endl;
	return b;
	
}
	double squareArea(double & a){     
	double b;
	b = a*a;
	if (a<0)
		bool die ("side is negative");
	else
	cout << "The perimeter of the square is " << b << endl;
		  return b;

}

When i declare them i get a bunch of errors sych as LNK

Error	1	error LNK2005: _main already defined in test.obj	test2.obj
Error	4	error LNK2019: unresolved external symbol "bool __cdecl getDouble(double,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (?getDouble@@YA_NNABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z) referenced in function _main	test2.obj

The declarations of your functions don't match the definitions. In particular, there's a mismatch in passing a plain double versus a reference to a double. However, in the interests of expediting a solution, here's your fixed code:

#include <cmath>
#include <iostream>
#include <string>

using namespace std;

bool die(const string & msg);
bool getDouble(double& a, const string & b);
double squarePerimeter(double a);
double squareArea(double a);

int main(){

    double a = 0;

    cout << getDouble(a, "Enter length of side");
    cout << squarePerimeter(a);
    cout << squareArea(a);

    return 0;
}

bool die(const string & msg){
    cout << msg << endl;
    exit(EXIT_FAILURE);	 
}

bool getDouble(double& a, const string& b){

    cout << b;
    if(cin>>a)
        return true;
    else 
        return false;
}

double squarePerimeter(double a){
    double b;
    b = 4*a;
    if (a<0)
        bool die("side is negative");
    else 
        cout << "The perimeter of the square is " << b << endl;
    return b;
}

double squareArea(double a){     
    double b;
    b = a*a;
    if (a<0)
        bool die ("side is negative");
    else
        cout << "The perimeter of the square is " << b << endl;
    return b;
}

See if you can point out what I changed and speculate why I made the change. That will help you learn.

You have arguments to your 3 functions but you haven't declared or initialized them before using them. Additionally, your function prototypes don't match your functions' definitions.

I think I see what you are trying to do, but you haven't implemented it correctly. This is what you need to do to do that correctly:

#include <iostream>

using namespace std;

void getIntInput(int &);

int main() {
  int inputValue = 0;                      //declare the input variable

  getIntInput(inputValue);                 //get the input value

  cout << "The value was: " << inputValue; //display the value

  return 0;
}

void getIntInput(int &value) {
  cout << "Please enter a value: ";
  cin >> value;
}

EDIT:
Oops, looks like Narue's got it covered...

Edited 6 Years Ago by Fbody: n/a

What does it mean if I have

Error	1	error LNK2005: _main already defined in test.obj	test2.obj

and 
Error	2	fatal error LNK1169: one or more multiply defined symbols found		1

>error LNK2005: _main already defined in test.obj
This means you probably have two definitions of main in the project. There are a number of ways to trigger such an error, but the most common in my experience is Java programmers who use a test main for their class libraries.

In your case, just search all of the files in your project for "main". You'll likely find something suspicious, though if you used the code I gave you exactly as posted, that error won't show up. ;)

alright thanks for your help!! I greatly appreciate it!!! Time to study. :]

By the way, when I said to point out the changes in my code and speculate, I was giving you an assignment. Please complete the assignment and post your answers here if you have the spare time. This kind of exercise is very instructive, especially when you have someone knowledgeable who can correct any misunderstandings as they arise.

This article has been dead for over six months. Start a new discussion instead.