-4

The goal of my assignment is to convert US dollars to Euros. All I need to do is prompt the user of an input and then use functions to get the output Im new to coding, and for the life of me can not find where I went wrong in declaring this function. any advice is appreciated.

#include <iostream>
using namespace std;

double getmoney();
double convert();
double display();

int main()
{

   cout.setf(ios::fixed);
   cout.setf(ios::showpoint);
   cout.precision(2);

   getmoney();

 display();



   return 0;

}

 double getmoney()
 {
         double money;
 cout << "Please enter the amount in US Dollars: ";
         cin >> money;
         return money;
}

 double convert(double money)
{
        double euros;
        euros = money * 1.41;
        return euros;
}

 double display(double money)
 {
         cout.setf(ios::fixed);
        cout.setf(ios::showpoint);
        cout.precision(2);

        double salad = convert(money);

         cout << getmoney() << endl;
      if (money >= 0)

           cout << "Euros: " << salad;

        else (money < 0);

                cout << "Euros: "  << "(" << salad << ")";

             return 0;
}
  • 5
    You have declared display() as taking no parameters, and then defined it as taking a double. Declaration and definition must match up, else you potentially have two completely different functions. –  May 16 '18 at 21:57
  • 2
    It seems you could use [a good book or two](https://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list/388282#388282). – Some programmer dude May 16 '18 at 21:58
  • 3
    `euros = money * 1.41;` Are you sure that's the correct way to convert USD to EUR?.. – bipll May 16 '18 at 21:59
  • @Some What should the compiler complain about? –  May 16 '18 at 22:19

2 Answers2

1

First you declared display as a function which doesn't take any arguments.

double display();

But when you defined the function, the function is taking an argument of type double.

double display(double money)

The declaration and definition should match so that compiler will know which function to jump when you used the function in your code.

In your case as declaration and definition are different, compiler doesn't know where to jump when you used display() in main() function. Hence undefined reference error.

kadina
  • 5,042
  • 4
  • 42
  • 83
0

Your function called "display" is declared at the top as having no arguments in the function call.

double display();

Then later you define this function like it should receive an argument.

double display(double money);

The compiler doesn't know what to do with these conflicts, so it will treat it as the first function having no definition.

[edit: posted right after I saw the almost identical first answer]

MPops
  • 355
  • 3
  • 8