Help with functions and classes

I can't compile my program. I know it is because I am not declaring my functions and passing my variables correctly with in the class. I'm getting two errors for my function in lines 12-14 (prototype of functions is does not match in class) and thens errors for my description of the functions declared in the class (canidate is 'name of function'). Obviously I don't know what these errors mean. Any help or examples would be greatly appreciated. Thanks.

Below is my code:

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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#include <iostream>

using namespace std;

//Name and members of class
class exchange

{
    public:
void showSelection();
void displayExchange(char& ch, double& num) const;
void outputType (char& type);
void convert (char& letter, double& num1);


private:

char moneyType;
double moneyAmount;

};



int main()

{
// object
exchange myMoney;

//calling showselection from class exchange
myMoney.showSelection();



return 0;

}

//function showSelection to get currency
void exchange::showSelection()
{

  cout<< "This program is to exchange your currency into other currencies \n\n" << endl;
  cout<< " Select your Currency \n"  << endl;
  cout << "(P) for pesos, (D) for U.S. dollars \n" << endl;
  cout << "(F) for Swiss francs, " "(E) for Euros, and\n" << endl;
  cout << "(Q) for quit program" << endl;
  cin>> moneyType;
  moneyType = static_cast<char>(toupper(moneyType));

//loop selection
  while (moneyType != 'Q')
{
    switch (moneyType)
    {
        case 'P':
        case 'D':
        case 'F':
        case 'E':
        cout << "Enter money amount";
        cin >> moneyAmount;
        //function to display currency exchange
        displayExchange(moneyType, moneyAmount);

        break;
        case 'Q':
        cout<<"closing program";
        break;
        default :
        cout << "Invalid selection" << endl;
    }

cout<< "This program is to exchange your currency into other currencies \n\n" << endl;
  cout<< " Select your Currency \n"  << endl;
  cout << "(P) for pesos, (D) for U.S. dollars \n" << endl;
  cout << "(F) for Swiss francs, " "(E) for Euros, and\n" << endl;
  cout << "(Q) for quit program" << endl;
  cin>> moneyType;
  moneyType = static_cast<char>(toupper(moneyType));

}}
//function to print out display of currency
void exchange::displayExchange(char moneyType, double moneyAmount) const
{

 cout << " MoneyType = " << outputType (moneyType) << "\n Amount = " << moneyAmount;
 cout <<  "\n Exchange in U.S. dollars = " << convert(moneyAmount);
 cout << endl;

}

//function to output type of money
void exchange::outputType (char moneyType)
{

    if (moneyType = 'P')
    cout << "pesos";
    else if (moneyType = 'D')
    cout << "dollars";
    else if (moneyType = 'F')
    cout << "Swiss Francs";
    else (moneyType = 'E')
    cout << "Euros";
}
//functione to convert currency
void exchange::convert(char moneyType, double moneyAmount)
{

    if (moneyType = 'P')
    cout << moneyAmount * 9.815;
    else if (moneyType = 'D')
    cout << moneyAmount;
    else if (moneyType = 'F')
    cout << moneyAmount * 1.4054;
    else (moneyType = 'E')
    cout << moneyAmount * .9553;

}



Check your function declarations:
void displayExchange(char& ch, double& num) const;
void outputType (char& type);
void convert (char& letter, double& num1);

You have to put a '&' in function definitions too!




~Gorav
http://www.kgsepg.com
Topic archived. No new replies allowed.