Multiple definitions found...ug.

Ok, I've included my other source files in my main.cpp on my calculator program. However, when I compile it tells me there is multiple definitions of my functions for addition, etc. what is going on here? This is what I have:

#include <cstdlib>
#include <iostream>
#include "output.cpp" // This source file includes the functions that prompt for number entry upon selection.
#include "algorithm.cpp" // This source file contains math functions to do addition, multiplication, etc.

using namespace std;


int main ()
{
int Oper;

cout << "Please select an operations:\n";
cout << "1. Addition\n";
cout << "2. Subtraction\n";
cout << "3. Multiplication\n";
cout << "4. Division\n";

cout << "\nChoice: ";
cin >> Oper;
cout << endl;

switch(Oper)
{
case 1:
addout(); // addout(), subout(), etc are the functions included in output.cpp
addition(); // addition(), subtraction(), etc are the functions included in algorithm.cpp
break;
case 2:
subout();
subtraction();
break;
case 3:
multout();
multiplication();
break;
case 4:
divout();
division();
break;
default: "You have chosen an incorrect choice.";
}

system("PAUSE");
return 0;
}



The functions for division(), multiplication(), etc, is what I'm getting errors on.

Here is the source file for my math functions:

include <iostream>

using namespace std;

int total = 0; // The value to hold the answer to the equation.
const int MAX = 10; // This constant is the max input allowed of the user.
int numArray[ MAX ]; // This is the array that user input will be placed into, it will allow for 10 numbers only.
int i = 0; // This is the variable that will be used to gather input from user, and place input into an numArray.



double addition() // The addition function will add user input, allowing decimals.
{
do{
cin >> numArray[ i ];
total += numArray[ i ];
i++;
}while(i < 10);

cout << "\n" << total << endl << endl; // Returns the sum of the numbers entered in the array.

return 0;
}

double subtraction()
{
do{
cin >> numArray[ i ];
total -= numArray[ i ];
i++;
}while(i < 10);

cout << "\n" << total << endl << endl;

return 0;
}

double multiplication()
{
do{
cin >> numArray[ i ];
total *= numArray[ i ];
i++;
}while(i < 10);

cout << "\n" << total << endl << endl;

return 0;
}

double division()
{
do{
cin >> numArray[ i ];
total /= numArray[ i ];
i++;
}while(i < 10);

cout << "\n" << total << endl << endl;
}
Last edited on
Don't include cpp files. You link to them, you don't include them.

Read this: http://cplusplus.com/forum/articles/10627/
Last edited on
default: "You have chosen an incorrect choice.";


What is that supposed to do??
A switch checks the value given within the variable inside its parameter , in this case, Oper. If any of the given cases are inputted, it switches the corresponding case, performing the given operations. For example If no case was given, it returns the default. If '1' was the value of Oper, it performs the given operation for Case 1. Switches are good if you need your program to do different things depending on input.

Don't include cpp files. You link to them, you don't include them.

Read this: http://cplusplus.com/forum/articles/10627/


Thanks!
Last edited on
L B meant to point out that your default case doesn't do anything. If you meant to print that string, you have to give it to cout.
Fixed.
Topic archived. No new replies allowed.