conversion

I worked on a conversion that converts dollars to Euros and I had no idea how to get it to compile, I had all sorts of issues. Can someone look at my code and tell me what is wrong?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
  #include <iostream>
#include <iomanip>
using namespace std;
/******************************************************************/
float dollarstoEuros(float dollars)
{
   cout.setf(ios::fixed);
   cout.setf(ios::showpoint);
   cout.precision(4);

   float Euros;

   Euros = dollars * 1.41;
   return Euros;
}

float isNegative(dollarstoEuros(float dollars))
{
   cout.setf(ios::fixed);
   cout.set(ios::showpoint);
   cout.precision(4);

   if (dollarstoEuros(dollars) < 0)
      return "("dollarstoEuros(dollars)")";

   else if (dollarstoEuros(dollars)>= 0
            return dollarstoEuros(dollars);
}


float main()
{
   cout.setf(ios:fixed);
   cout.setf(ios::showpoint);
   cout.precision(4);

   float dollars;
   float dollarstoEuros(dollars);
   bool isNegative(dollarstoEuros);

   cout << "Please enter the amount in US Dollars: $";
   cin >> dollars >> endl;

   cout << "/tEuros: " << isNegative(dollarstoEuros(dollars)) << endl;
}

The best way to do this is for you to tell us the first error the compiler gives you.

Anyway, float main() is wrong. int main() is right.

float isNegative(dollarstoEuros(float dollars)) just makes no sense at all.
I had the bool IsNegative(dollartoEuros(float dollars)) before and it was going to determine whether the function was positive or negative, if negative then put a set of parantheses around it.
It looks like your isNegative function is trying to build a string to output instead of returning just a number or a true/false value? I'm not sure what requirements you have. I've modified your code a bit to have the function do the display itself.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include <iostream>
#include <iomanip>
using namespace std;

float dollarstoEuros(float dollars)
{
    return dollars * 1.41;
}

void displayConversion(float dollars)
{
    cout.setf(ios::fixed);
    cout.setf(ios::showpoint);
    cout.precision(4);

    float euros = dollarstoEuros(dollars);
        
    if (euros < 0)
        cout << "\nUS$ " << dollars << "\tEuros (" << euros << ")" << endl;
    else
        cout << "\nUS$ " << dollars << "\tEuros  " << euros << endl;
}


int main()
{
    float dollars;
 
    cout << "Please enter the amount in US Dollars: $";
    cin >> dollars;

    displayConversion(dollars);
    
    return 0;
}
Please enter the amount in US Dollars: $
US$ -300.0000	Euros (-423.0000)
Last edited on
thank you so much, I'm pretty new at this and got my syntax all jacked up, anyways thanks for the help!
Topic archived. No new replies allowed.