# Thread: Need help with this simple conversion program

1. ## Need help with this simple conversion program

How do i get the constant value to be a value entered by the user. The only way i can get this to work is to make it a constant.

The program works fine for now. I just dont get why my exchange cannot use the value when its not a constant?????

Also i want to figure out how to get the exRate entered once in the loop instead of over and over.

Code:
```#include <iostream>
#include <math.h>
#include <iomanip>
using namespace std;

class Exchange
{
public:
float exRate;
float BritishPound;
float USDollar;
};

void main()
{

cout << "Lets process 3 british pound amounts and convert to US dollars" << "\n";

int const values = 3;

if (values==0) {
cout << "Error with input! please run program again!";
}
Exchange test[values];
for(int i=0; i < values; i++)
{
cout << "Enter in British to US conversion rate:  ";
cin >> test[i].exRate;
cout << "Enter British Value to convert: ";
cin  >> test[i].BritishPound;
test[i].USDollar = (test[i].BritishPound * test[i].exRate);
}

cout << setw(10) << "\nExchange Rate      " <<setw(15) << "British pounds to convert     "
<< setw(10) << "US money    " << "\n";

for(int j=0; j < values; j++)
{
cout<<setiosflags(ios::fixed | ios::showpoint)<<setprecision(2)
<< setw(3) << test[j].exRate<<setw(20)<< test[j].BritishPound
<<setw(30) << test[j].USDollar << "\n";
}
}```

2. You can't change a const value at all. It is meant to never ever change while the program is running. You can change it in the code, but not while running the program. Also, before other people decide to get you for this, change void main to int main... void is just a bad thing for main...

In fact I am having a hard time figuring out what you want. Did you want to always have 3 British pound values or do you want that to change?

3. In C++ you must use a constant size for an array (although it is allowed in C and on some compilers as an extension). The alternative is to use dynamic memory allocation.

The best way to do that in C++ is to use a vector to store your Exchange objects. You can also use new[] to allocate space dynamically for the array, but you also must remember to call delete[] in order to free the memory and destruct all the objects.

That might be overkill for this program. You could just make a really big array (like 100) and then error out if the user enters more than 100 for the number of values.

4. > void main()
Still not read the FAQ huh?