A bit confused as to what this variable/function/whatever this thing is.

...
Last edited on
enums are variables that can have only one of the given values.

Here, the typename of the enum is 'exType'. And possible values are 'BUY' and 'SELL'

You declare instances of the enum just like any other variable, and assign/compare the same way:

1
2
3
4
5
exType exchange;  // like saying "int myvar;", it creates a variable of type 'exType' named 'exchange'

exchange = BUY;  // set it to 'BUY'

if(exchange == SELL) // does it equal 'SELL'? 


That's all there is to it.
...
Last edited on
It's a scope problem. exType can't be defined in main. Just as you can't use a variable declared in main in another function, you can't use a type (in this case exType) that's defined in another function.

You need to put exType's definition in a broader scope. Probably global.

What is exType ex mean?


I thought I explained that in my post.

it creates a variable of type 'exType' named 'ex'.

1
2
3
int myvar;  // creates an int named myvar

exType ex;  // create an exType named ex 
Last edited on
...
Last edited on
For future reference, it helps if you post the errors as well.

Anyway I tried compiling and got 1 warning and 2 errors.

main.cpp(19): warning C4700: uninitialized local variable 'exch' used

This warning is just what it says.

1
2
3
int exch;  // you create exch here, but don't initialize it

while (exch == 1 || exch ==2 || exch ==3 || exch ==4 || exch <=0 || exch >=6)  // then you immediate use it 


If you don't initialize your variables, then their contents are unpredictable. exch might be 0, or it might be 5, or it might be -65461377. There's no way to know unless you assign it.

As for the errors:
1
2
1>main.cpp(90): error C4716: 'changeRate' : must return a value
1>main.cpp(107): error C4716: 'showMenu' : must return a value


Again these are pretty self explanitory. Your changeRate and showMenu functions are supposed to return a value, but you aren't returning anything.
...
Last edited on
it works fine in my compiler o-o


That doesn't matter. It's wrong and needs to be fixed. Variables are unpredicatable if uninitialized. You need to initialize it if you're going to be reading it right away.

If it happens to work for you you are just getting [un]lucky. The same program running on someone else's computer might not work for them.

As to my question now is Since BUY and SELL from enum exType {BUY, SELL};
How do I make it when I input 1 it asked how much I'm buying . Because atm it asks how much I'm buying but right after asks how much is selling.


This is the same problem. You have your variable 'ex', but you never set it to anything. You have to set it to what you want before you can read from it.


Also -- you don't need that global exType ex;. Get rid of it. Earlier I meant the enum itself had to be global.
...
Last edited on
Dammit. I suspected as much.

Unfortunatly all I can restore is the source

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
#include <iostream>

using namespace std;

double changeRate ();
void showRates(double rate);//function to show rate
int showMenu(double rate); //function to show menu
double rate = 0.7333;// default rate Global Variable
enum exType {BUY, SELL};
double exchangeCurrency (double rate, exType ex);

int main()
{
enum exchange {SellEuro = 1, BuyEuro, ChangeRate, ShowRate, Exit};


int exch;

while (exch == 1 || exch ==2 || exch ==3 || exch ==4 || exch <=0 || exch >=6)
{
    showMenu(rate);
    cin>>exch;
    cout<<endl;
    cout.setf(ios::fixed | ios::showpoint);
    cout.precision(2);
double amount;//input amount    
switch(exch)
{
    case SellEuro:
    {
        // exchangeCurrency(rate, ex);
         break;
    }
    case BuyEuro:
    {
         cout<<"Buying Euro: Enter the amount to exchange: ";
         cin>>amount;
         cout<<endl;
         cout<<"You will get "<<amount/(rate*0.96)<<" USD"<<endl<<endl<<endl;
         break;
    }
    case ChangeRate:
    {
         changeRate();
         break;
    }
    case ShowRate:
    {
          showRates(rate);
          cout<<endl<<endl;
          break;
    }
    case Exit:
    {
         cout<<"Exiting . . . "<<endl<<endl;
    break;
    }
    default: cout<<"That is not a valid choice."<<endl<<endl<<endl;
    
    
}  

}
system("Pause");
return 0;
}
//double exchangeCurrency (double rate, exType ex)
  // {
    //   cout<<"Selling Euro: Enter the amount to exchange: ";
      // cin>>amount;
      // cout<<endl;
      // cout<<"You will get "<<amount/(rate*1.04)<<" USD"<<endl<<endl<<endl;
   //} 
void showRates(double rate)
   {
    cout.setf(ios::fixed | ios::showpoint);
    cout.precision(4); 
         cout<<"The current rate is:      "<<rate<<endl;
         cout<<"The current BUY rate is:  "<<rate*1.04<<endl; 
         cout<<"The current SELL rate is: "<<rate*0.96<<endl;   
         cout<<endl;
   }

double changeRate ()
   {
       cout<<"Enter new rate: ";
       cin>>rate;
       cout<<endl<<endl;
       
   } 
int showMenu(double rate)
   {
                 cout<<"CURRENCY EXCHANGE Euro<>US"<<endl<<endl;
    cout<<"---------------------------"<<endl<<endl;
    cout<<"       BUY RATE   SELL RATE"<<endl;    
    cout.setf(ios::fixed | ios::showpoint);
    cout.precision(4);
    cout<<"$1 =     "<<rate*1.04<<"      "<<rate*0.96<<endl<<endl;

     cout<<"Select the option "<<endl<<endl
         <<"1. Sell Euro"<<endl<<endl
         <<"2. Buy Euro"<<endl<<endl
         <<"3. Change Exchange Rate"<<endl<<endl
         <<"4. Show Exchange Rate"<<endl<<endl
         <<"5. Exit"<<endl<<endl
         <<">> ";   
   }


PS: don't be a douche. The whole reason I didn't want to answer in PM is because I wanted it to be public so other people could benefit from it. If you erase your posts it defeats the point.
Last edited on

As Disch made clear, here's the original post for the benefit of others.

So, I'm in compsci first year in college and I have an assignment where I'm a very confused to what it means.

I don't want to spend a long time explaining the description and meaning for the program so to sum it all up, it's about exchange rates with buy or sell for euro to USD
I'm not sure if it's required to give all the information but I'm required to use the following functions:

double exchangeCurrency (double rate, exType ex);
double changeRate ();
void showRates(double rate);
int showMenu(double rate);
where exType is defined as enum exType {BUY, SELL};.

I've used all the other function EXCEPT exchangeCurrency because I have no clue what exType ex is .Well, I know exType is an enumeration which is an integer but I don't know what "ex" is or what I'm supposed to do with it . When I put it into my program I get multiple errors about exType and such. I know I'm not explaining clearly but I will be glad to explain in more detail after input on whether or not I need more detail. lol. All help is greatly appreciated .

Well , if details are needed this link is the link to the PDF file for the assignment
http://www2.cs.uh.edu/~acl/cs1410/Assignment/prog4.pdf
Last edited on
I really don't understand why people do this... maybe they're afraid someone's gonna find out they looked for help?
don't be shameful for asking something. asking is good... (one of my mottoes :D)
Probably because it was a class exercise or even exam and they want to delete all traces. Which is stupid, as forums log.
Topic archived. No new replies allowed.