Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How come this doesn't work? Please help

Status
Not open for further replies.

DaRedMonkey

IS-IT--Management
Aug 23, 2002
17
US

The following program give me these error:

ompiling...
AnyCurrency2US.cpp
E:\DVN\UOP\POS370\Week3\Currency_Conversion\AnyCurrency2US.cpp(61) : error C2440: '=' : cannot convert from 'char [4]' to 'char [20]'
There is no context in which this conversion is possible
E:\DVN\UOP\POS370\Week3\Currency_Conversion\AnyCurrency2US.cpp(65) : error C2440: '=' : cannot convert from 'char [5]' to 'char [20]'
There is no context in which this conversion is possible
E:\DVN\UOP\POS370\Week3\Currency_Conversion\AnyCurrency2US.cpp(69) : error C2440: '=' : cannot convert from 'char [9]' to 'char [20]'
There is no context in which this conversion is possible
E:\DVN\UOP\POS370\Week3\Currency_Conversion\AnyCurrency2US.cpp(73) : error C2440: '=' : cannot convert from 'char [15]' to 'char [20]'
There is no context in which this conversion is possible
E:\DVN\UOP\POS370\Week3\Currency_Conversion\AnyCurrency2US.cpp(77) : error C2440: '=' : cannot convert from 'char [18]' to 'char [20]'
There is no context in which this conversion is possible
Error executing cl.exe.

Currency_update_proj.exe - 5 error(s), 0 warning(s)



==================================




void main(void)
{
// Variable declaration
const double JPY_Rate = 117.70; // Rate to convert YEN (JPY) to US Dollar
const double EUR_Rate = 1.021; // Rate to convert EURO (EUR) to US Dollar
const double CAD_Rate = 1.559; // Rate to convert Canadian Dollar (CAD) to US Dollar
const double GBP_Rate = 0.652; // Rate to convert Pounds Stering (GBP) to US Dollar
const double AUD_Rate = 1.833; // Rate to convert Australia Dollar (AUD) to US Dollar
bool Continue = true; // Flag use to determine if the user want to do another conversion
char Cont; // Holds choice to continue or not
bool Error = false; // Flag to respond to invalid input
char Choice = ' '; // Value to hold the choice of currency
char CurrencyName[20]; // Holds the long name of the currency
double CurrencyRate; // Holds the exchange value fora particular currency
double OrigAmount; // The amount entered by use to convert to USD
double ConvertedAmount; // The amount in USD after the conversion

while( Continue ){

// Display Title
cout << &quot;\tC U R R E N C Y C O N V E R S I O N&quot; << endl;
cout << &quot;\t_____________________________________&quot; << endl << endl;

// Prompt for Input
cout << &quot;What currency would you like to convert to US Dollars?&quot; << endl;
cout << &quot;\tY for YEN&quot; << endl;
cout << &quot;\tE for Euro&quot; << endl;
cout << &quot;\tC for Canadian&quot; << endl;
cout << &quot;\tB for British Pounds&quot; << endl;
cout << &quot;\tA for Australian dollar&quot; << endl;
cout << &quot;What's your choice Y, E, C, B, or A ? &quot; << endl << endl;

cin >> Choice;

// Setup the appropriate currency type and rate
switch(Choice){
case 'Y':
CurrencyName = &quot;Yen&quot;;
CurrencyRate = JPY_Rate;
break;
case 'E':
CurrencyName = &quot;Euro&quot;;
CurrencyRate = 1.021;
break;
case 'C':
CurrencyName = &quot;Canadian&quot;;
CurrencyRate = JPY_Rate;
break;
case 'B':
CurrencyName = &quot;British Pounds&quot;;
CurrencyRate = JPY_Rate;
break;
case 'A':
CurrencyName = &quot;Australian dollar&quot;;
CurrencyRate = JPY_Rate;
break;
default:
Error = true;
}


if ( Error == false ){

// Ask user for amount to be converted
cout << &quot;Please enter the amount in &quot; << CurrencyName << &quot; to convert into US Dollars ? &quot;;
cin >> OrigAmount;

// Perform conversion
ConvertedAmount = OrigAmount * CurrencyRate;

// Print out result of conversion
cout << &quot;As of 08/15/02 : &quot; << OrigAmount << &quot; of &quot; << CurrencyName << &quot; is equivalent to&quot;;
cout << ConvertedAmount << &quot; US Dollar(s).&quot; << endl << endl;

} else {
cout << &quot;Error: The choice you have entered is not valid.&quot; << endl;
}


cout << &quot;Do you want to do try another conversion (Y or N)? &quot; << endl;
cin >> Cont;

}




if ( Cont = 'N' ) {
Continue = false;

cout << &quot;Enter any key to exit ...&quot;;
getch();

}

} // End Main
 
CurrencyName = &quot;Yen&quot;;

this must be:

strcpy ( CurrencyName, &quot;Yen&quot;);

The same for the other CurrencyName = &quot;...&quot; statements.

For this to work, you must put:
#include <string.h>

at the beginning of the source. Marcel
 

Thank you very much Marcel. I am very new at Visual C++. Kind people like you make this a nicer experience. I really appreciated. Thank you.

--Dan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top