• C

# Problems

I am still very confused. I have worked on this for 2 full days and it still gives me errors. I am at a stand still.  /******************************************************************************************************/

/*Currency Conversion Program created by Rebecca Fusco 8/4/04*/

/*five selected world currency conversions to 1.00 US dollar,float datatype*/
int main(void)

{                        /*beginning function*/
/*world country selections for currency conversions:Canada,Europe,United Kingdom,Japan,Russia,United States*/

at http://www.xe.com/effective as of 8/4/04 18:44 GMT*/
EUR=0.829643f;
GBP=0.548242f;
JPY=110.631f;
RUR=29.1800f;
US=1.00f;

printf("Currency Conversion\n\n");          /*displays title and double space*/
/*declare variables for currency rate from European Euro converted to the United States Dollar*/
printf("%f European Euro is equivalent to %f US Dollar\n",EUR,US);
/*declare variables for currency rate from United Kingdom Pound to the United States Dollar*/
printf("%f United Kingdom Pound is equivalent to %f US Dollar\n",GBP,US);
/*declare variables for currency rate from Japanese Yens to the United States Dollar*/
printf("%f Japanese Yens is equivalent to %f US Dollar\n",JPY,US);
/*declare variables for currency rate from Canadian Dollars to the United States Dollar*/
/*declare variables for currency rate from Russian Rubles converted to the United States Dollar*/
printf("%f Russian Rubles is equivalant to %f US Dollar\n",RUR,US);

getch();
convert();
return 0;
}                                   /*ends*/

/**************************************************************************************************/
/*Select a currency conversion type by code number 8/11/04*/
#include <stdio.h>
int main(void)

{
printf("Select a currency type\n\n");
printf("1=European Euro 2=United Kingdom Pound 3=Japanese Yens 4=Canadian Dollars 5=Russian Rubles\n");
printf("Select the 4=Canadian Dollars currency type\n\n");
}
EUR=1;
GBP=2;
JPY=3;
RUR=5;
char option;
option=getch();
if EUR==1);
{
else if(GBP==2);
else if (JPY==3);
else if (RUR==5);
}
printf("Number 4 Canadian Dollars has been selected\n\n");

EUR=0.829643f;
GBP=0.548242f;
JPY=110.631f;
RUR=29.1800f;
US=1.00f;
printf("The selected currency type is the Canadian dollar of %f equivlwnt to %f US Dollar\n"CAD,US};
getch();
convert();
return 0;
}

###### Who is Participating?

x

Commented:
>> I understand now that the option is what ever you assign it so the 255 is just a randomly picked number.

Random as in terms of out of the range of values you want to test. Initially, I wrote "0" until realizing that this is our exit condition.
0

Commented:
Sorry, but that code is a mess - cleaned out most of the errors, you will need to start over from there:

/**************************************************************************************************/

/*Select a currency conversion type by code number 8/11/04*/
#include <stdio.h>
int main(void)

{

char option;

EUR=1;
GBP=2;
JPY=3;
RUR=5;

fEUR=0.829643f;
fGBP=0.548242f;
fJPY=110.631f;
fRUR=29.1800f;
fUS=1.00f;

printf("Select a currency type\n\n");
printf("1=European Euro 2=United Kingdom Pound 3=Japanese Yens 4=Canadian Dollars 5=Russian Rubles\n");
printf("Select the 4=Canadian Dollars currency type\n\n");

option=getch();

if (option=='4') printf("Number 4 Canadian Dollars has been selected\n\n");

printf("The selected currency type is the Canadian dollar of %f equivlwnt to %f US Dollar\n", fCAD,fUS);
getch();
convert();
return (0);
}
0

Author Commented:
Sorry but I am new to programming. I am getting a parse errorC:\Program Files\Miracle C\CC.c: line 69: Parse Error, expecting `')'' or `',''
'printf("The selected currency type is the Canadian dollars of %f equivlwnt to %f US Dollar\n",fCAD,fUS}'
aborting compile which mean it is missing brackets or par..but I cannot find it? I am error checking the numbers to validate whether its correct. Do I have to add in the else if for each number to do that? Thanks   e /******************************************************************************************************/

/*Currency Conversion Program created by Rebecca Fusco 8/4/04*/

/*five selected world currency conversions to 1.00 US dollar,float datatype*/
int main(void)

{                        /*beginning function*/
/*world country selections for currency conversions:Canada,Europe,United Kingdom,Japan,Russia,United States*/

at http://www.xe.com/effective as of 8/4/04 18:44 GMT*/
EUR=0.829643f;
GBP=0.548242f;
JPY=110.631f;
RUR=29.1800f;
US=1.00f;

printf("Currency Conversion\n\n");          /*displays title and double space*/
/*declare variables for currency rate from European Euro converted to the United States Dollar*/
printf("%f European Euro is equivalent to %f US Dollar\n",EUR,US);
/*declare variables for currency rate from United Kingdom Pound to the United States Dollar*/
printf("%f United Kingdom Pound is equivalent to %f US Dollar\n",GBP,US);
/*declare variables for currency rate from Japanese Yens to the United States Dollar*/
printf("%f Japanese Yens is equivalent to %f US Dollar\n",JPY,US);
/*declare variables for currency rate from Canadian Dollars to the United States Dollar*/
/*declare variables for currency rate from Russian Rubles converted to the United States Dollar*/
printf("%f Russian Rubles is equivalant to %f US Dollar\n",RUR,US);

getch();
convert();
return 0;
}                                   /*ends*/

/**************************************************************************************************/
/*Select a currency conversion type by code number 8/11/04*/
#include <stdio.h>
int main(void)

{

char option;
EUR=1;
GBP=2;
JPY=3;
RUR=5;

fEUR=0.829643f;
fGBP=0.548242f;
fJPY=110.631f;
fRUR=29.1800f;
fUS=1.00f;
printf("Select a currency type\n\n");
printf("1=European Euro 2=United Kingdom Pound 3=Japanese Yens 4=Canadian Dollars 5=Russian Rubles\n");
printf("Select the 4=Canadian Dollars currency type\n\n");
option=getch();
if(option=='4') printf("Number 4 Canadian Dollars has been selected\n\n");
printf("Number 4 Canadian Dollars has been selected\n\n");
printf("The selected currency type is the Canadian dollars of %f equivlwnt to %f US Dollar\n",fCAD,fUS};
getch();
convert();
return 0;
}

0

Commented:
>>'printf("The selected currency type is the Canadian dollars of %f equivlwnt to %f US Dollar\n",fCAD,fUS}

That's one of the errors I corrected above (why did you use that line again? :o) - it has to end with a ');', e.g.

printf("The selected currency type is the Canadian dollars of %f equivlwnt to %f US Dollar\n",fCAD,fUS);

0

Author Commented:
Dah!  I totally missed that. It is always something small and silly that you should catch. You are the best ever :-) So this error checks my program also? Or do I need to work on it more? Thanks Rebecca
0

Commented:
You still need to define your 'convert()' function (if you still need it), apart from that, it *compiles* (which does nto mean that it will work). Since this seems to be an assignment, I won't give you the full code, but to outline what you should do:

Remove the

if (option=='4') printf("Number 4 Canadian Dollars has been selected\n\n");
printf("The selected currency type is the Canadian dollar of %f equivlwnt to %f US Dollar\n", fCAD,fUS);

switch(option) {

case '1':

printf("The selected currency type is the Euro of %f equivlwnt to %f US Dollar\n", fEUR,fUS);
break;

case '2':

printf("The selected currency type is the United Kingdom Pound of %f equivlwnt to %f US Dollar\n", fGBP,fUS);
break;

default:
printf("The selected currency type is invalid.\n");
}
0

Author Commented:
/******************************************************************************************************/

I took out the'convert()' function as I do not think that I need it. Now I am getting a 2 default error message? I am lost on that one. C:\Program Files\Miracle C\CC.c: line 84: two defaults
'default: printf("The selected currency types 1,2,3,5 are invalid\n")'
aborting compile

/*Currency Conversion Program created by Rebecca Fusco 8/4/04*/

/*five selected world currency conversions to 1.00 US dollar,float datatype*/
int main(void)

{                        /*beginning function*/
/*world country selections for currency conversions:Canada,Europe,United Kingdom,Japan,Russia,United States*/

at http://www.xe.com/effective as of 8/4/04 18:44 GMT*/
EUR=0.829643f;
GBP=0.548242f;
JPY=110.631f;
RUR=29.1800f;
US=1.00f;

printf("Currency Conversion\n\n");          /*displays title and double space*/
/*declare variables for currency rate from European Euro converted to the United States Dollar*/
printf("%f European Euro is equivalent to %f US Dollar\n",EUR,US);
/*declare variables for currency rate from United Kingdom Pound to the United States Dollar*/
printf("%f United Kingdom Pound is equivalent to %f US Dollar\n",GBP,US);
/*declare variables for currency rate from Japanese Yens to the United States Dollar*/
printf("%f Japanese Yens is equivalent to %f US Dollar\n",JPY,US);
/*declare variables for currency rate from Canadian Dollars to the United States Dollar*/
/*declare variables for currency rate from Russian Rubles converted to the United States Dollar*/
printf("%f Russian Rubles is equivalant to %f US Dollar\n",RUR,US);

getch();
return 0;
}                                   /*ends*/

/**************************************************************************************************/
/*Select a currency conversion type by code number 8/11/04*/
#include <stdio.h>
int main(void)
{

char option;
EUR=1;
GBP=2;
JPY=3;
RUR=5;

fEUR=0.829643f;
fGBP=0.548242f;
fJPY=110.631f;
fRUR=29.1800f;
fUS=1.00f;

printf("Select a currency type\n\n");
printf("1=European Euro 2=United Kingdom Pound 3=Japanese Yens 4=Canadian Dollars 5=Russian Rubles\n");
printf("Select the 4=Canadian Dollars currency type\n\n");

option=getch();
{
case '1':
printf("The selected currency type is the European Euro of %f equivalant to %f US  Dollar\n",fEUR,fUS);
break;
case '2':
printf("The selected currency type is the United Kingdom Pound of %f equivalant to %f US  Dollar\n",fGBP,fUS);
break;
case'3':
printf("The selected currency type is the Japanese Yens of %f equivalant to %f US  Dollar\n",fJPY,fUS);
break;
case'4':
printf("The selected currency type is the Canadian DOllars of %f equivalant to %f US  Dollar\n",fCAD,fUS);
break;
case '5':
printf("The selected currency type is the Russian Rubles of %f equivalant to %f US  Dollar\n",fRUR,fUS);
break;
default:
printf("The selected currency types 1,2,3,5 are invalid\n");
break;
}
printf("Number 4 Canadian Dollars has been selected\n\n");
getch();
return 0;
}

0

Commented:
It should be

/*Select a currency conversion type by code number 8/11/04*/
#include <stdio.h>
int main(void)
{

char option;
EUR=1;
GBP=2;
JPY=3;
RUR=5;

fEUR=0.829643f;
fGBP=0.548242f;
fJPY=110.631f;
fRUR=29.1800f;
fUS=1.00f;

printf("Select a currency type\n\n");
printf("1=European Euro 2=United Kingdom Pound 3=Japanese Yens 4=Canadian Dollars 5=Russian Rubles\n");
printf("Select the 4=Canadian Dollars currency type\n\n");

option=getch();
switch(option)
{
case '1':
printf("The selected currency type is the European Euro of %f equivalant to %f US  Dollar\n",fEUR,fUS);
break;
case '2':
printf("The selected currency type is the United Kingdom Pound of %f equivalant to %f US  Dollar\n",fGBP,fUS);
break;
case'3':
printf("The selected currency type is the Japanese Yens of %f equivalant to %f US  Dollar\n",fJPY,fUS);
break;
case'4':
printf("The selected currency type is the Canadian DOllars of %f equivalant to %f US  Dollar\n",fCAD,fUS);
break;
case '5':
printf("The selected currency type is the Russian Rubles of %f equivalant to %f US  Dollar\n",fRUR,fUS);
break;
default:
printf("The selected currency types 1,2,3,5 are invalid\n");
break;
}
printf("Number 4 Canadian Dollars has been selected\n\n");
getch();
return 0;
}

since 'switch(CAD==4)' does not make any sense...
0

Commented:
I suspect the assignment is to input an amount in US \$, a currrency to convert it to, and then print out the \$ in terms of that currency (
(or the reverse).  To do that,  you'll have to add another prompt "Please enter the amount", another input, and then do a very little bit of math.

0

Author Commented:
Hi again :-) How come it only prints out up to the  the  printf("Select the 4=Canadian Dollars currency type\n\n");

and not after? Only prints up to when the switch starts? Thanks /******************************************************************************************************/

/*Currency Conversion Program created by Rebecca Fusco 8/4/04*/

/*five selected world currency conversions to 1.00 US dollar,float datatype*/
int main(void)

{                        /*beginning function*/
/*world country selections for currency conversions:Canada,Europe,United Kingdom,Japan,Russia,United States*/

at http://www.xe.com/effective as of 8/4/04 18:44 GMT*/
EUR=0.829643f;
GBP=0.548242f;
JPY=110.631f;
RUR=29.1800f;
US=1.00f;

printf("Currency Conversion\n\n");          /*displays title and double space*/
/*declare variables for currency rate from European Euro converted to the United States Dollar*/
printf("%f European Euro is equivalent to %f US Dollar\n",EUR,US);
/*declare variables for currency rate from United Kingdom Pound to the United States Dollar*/
printf("%f United Kingdom Pound is equivalent to %f US Dollar\n",GBP,US);
/*declare variables for currency rate from Japanese Yens to the United States Dollar*/
printf("%f Japanese Yens is equivalent to %f US Dollar\n",JPY,US);
/*declare variables for currency rate from Canadian Dollars to the United States Dollar*/
/*declare variables for currency rate from Russian Rubles converted to the United States Dollar*/
printf("%f Russian Rubles is equivalant to %f US Dollar\n",RUR,US);

getch();
return 0;
}                                   /*ends*/

/**************************************************************************************************/
/*Select a currency conversion type by code number 8/11/04*/
#include <stdio.h>
int main(void)
{

char option;
EUR=1;
GBP=2;
JPY=3;
RUR=5;

fEUR=0.829643f;
fGBP=0.548242f;
fJPY=110.631f;
fRUR=29.1800f;
fUS=1.00f;

printf("Select a currency type\n\n");
printf("1=European Euro 2=United Kingdom Pound 3=Japanese Yens 4=Canadian Dollars 5=Russian Rubles\n");
printf("Select the 4=Canadian Dollars currency type\n\n");

option=getch();
switch(option)
{
case '1':
printf("The selected currency type is the European Euro of %f equivalant to %f US  Dollar\n",fEUR,fUS);
break;
case '2':
printf("The selected currency type is the United Kingdom Pound of %f equivalant to %f US  Dollar\n",fGBP,fUS);
break;
case'3':
printf("The selected currency type is the Japanese Yens of %f equivalant to %f US  Dollar\n",fJPY,fUS);
break;
case'4':
printf("The selected currency type is the Canadian DOllars of %f equivalant to %f US  Dollar\n",fCAD,fUS);
break;
case '5':
printf("The selected currency type is the Russian Rubles of %f equivalant to %f US  Dollar\n",fRUR,fUS);
break;
default:
printf("The selected currency types 1,2,3,5 are invalid\n");
break;
}
printf("Number 4 Canadian Dollars has been selected\n\n");
getch();
return 0;
}

0

Commented:
You need to remove

printf("Number 4 Canadian Dollars has been selected\n\n");

That should be

/*Select a currency conversion type by code number 8/11/04*/
#include <stdio.h>
int main(void)
{

char option;
EUR=1;
GBP=2;
JPY=3;
RUR=5;

fEUR=0.829643f;
fGBP=0.548242f;
fJPY=110.631f;
fRUR=29.1800f;
fUS=1.00f;

printf("Select a currency type\n\n");
printf("1=European Euro 2=United Kingdom Pound 3=Japanese Yens 4=Canadian Dollars 5=Russian Rubles\n");
printf("Select the 4=Canadian Dollars currency type\n\n");

option=getch();
switch(option)
{
case '1':
printf("The selected currency type is the European Euro of %f equivalant to %f US  Dollar\n",fEUR,fUS);
break;
case '2':
printf("The selected currency type is the United Kingdom Pound of %f equivalant to %f US  Dollar\n",fGBP,fUS);
break;
case'3':
printf("The selected currency type is the Japanese Yens of %f equivalant to %f US  Dollar\n",fJPY,fUS);
break;
case'4':
printf("The selected currency type is the Canadian DOllars of %f equivalant to %f US  Dollar\n",fCAD,fUS);
break;
case '5':
printf("The selected currency type is the Russian Rubles of %f equivalant to %f US  Dollar\n",fRUR,fUS);
break;
default:
printf("The selected currency types 1,2,3,5 are invalid\n");
break;
}
getch();
return 0;
}

BTW, why are you always posting both variants?

0

Author Commented:
Still is not working? Should I not be able to print out something after the switch? I am still learning. How would I know if the switch is actually working? Thanks

#include <stdio.h>
int main(void)
{

char option;
EUR=1;
GBP=2;
JPY=3;
RUR=5;

fEUR=0.829643f;
fGBP=0.548242f;
fJPY=110.631f;
fRUR=29.1800f;
fUS=1.00f;

printf("Select a currency type\n\n");
printf("1=European Euro 2=United Kingdom Pound 3=Japanese Yens 4=Canadian Dollars 5=Russian Rubles\n");
printf("Select the 4=Canadian Dollars currency type\n\n");

option=getch();
switch(option)
{
case '1':
printf("The selected currency type is the European Euro of %f equivalant to %f US  Dollar\n",fEUR,fUS);
break;
case '2':
printf("The selected currency type is the United Kingdom Pound of %f equivalant to %f US  Dollar\n",fGBP,fUS);
break;
case'3':
printf("The selected currency type is the Japanese Yens of %f equivalant to %f US  Dollar\n",fJPY,fUS);
break;
case'4':
printf("The selected currency type is the Canadian DOllars of %f equivalant to %f US  Dollar\n",fCAD,fUS);
break;
case '5':
printf("The selected currency type is the Russian Rubles of %f equivalant to %f US  Dollar\n",fRUR,fUS);
break;
default:
printf("The selected currency types 1,2,3,5 are invalid\n");
break;
}
getch();
return 0;
}

0

Commented:
>> Still is not working?

Hmm, it works fine here. Or do you want that the user is *only* able to input '4'?

0

Author Commented:
I want to get a currency code or selection number from the menu and validate whether its correct and print the equivalent in US dollars. For example the program may accept the input like

Select the currency

1. Indian  Rupees
2.  Euro
3. Pound
0  Exit

0

Commented:

case '0':
printf("exiting...\n");
return (0);
break;

if you want it to run in a loop, that should be

/*Select a currency conversion type by code number 8/11/04*/
#include <stdio.h>
int main(void)
{

char option;
EUR=1;
GBP=2;
JPY=3;
RUR=5;

fEUR=0.829643f;
fGBP=0.548242f;
fJPY=110.631f;
fRUR=29.1800f;
fUS=1.00f;
while(1) {
printf("Select a currency type\n\n");
printf("1=European Euro 2=United Kingdom Pound 3=Japanese Yens 4=Canadian Dollars 5=Russian Rubles 0=exit\n");
printf("Select the 4=Canadian Dollars currency type\n\n");

option=getch();
switch(option)
{
case '1':
printf("The selected currency type is the European Euro of %f equivalant to %f US  Dollar\n",fEUR,fUS);
break;
case '2':
printf("The selected currency type is the United Kingdom Pound of %f equivalant to %f US  Dollar\n",fGBP,fUS);
break;
case'3':
printf("The selected currency type is the Japanese Yens of %f equivalant to %f US  Dollar\n",fJPY,fUS);
break;
case'4':
printf("The selected currency type is the Canadian DOllars of %f equivalant to %f US  Dollar\n",fCAD,fUS);
break;
case '5':
printf("The selected currency type is the Russian Rubles of %f equivalant to %f US  Dollar\n",fRUR,fUS);
break;
case '0':
printf("exiting...\n");
return (0);
break;
default:
printf("The selected currency types 1,2,3,5 are invalid\n");
break;
}

}
return 0;
}

0

Author Commented:
I give up :-( No matter what I do the printout only says: Select a currency type
1=European Euro 2=United Kingdom Pound 3=Japanese Yens 4=Canadian Dollars 5=Russian Rubles
Select the 4=Canadian Dollars currency type it never does show that it has picked number 4. Thanks

/*Select a currency conversion type by code number 8/11/04*/
#include <stdio.h>
int main(void)
{

char option;
EUR=1;
GBP=2;
JPY=3;
RUR=5;

fEUR=0.829643f;
fGBP=0.548242f;
fJPY=110.631f;
fRUR=29.1800f;
fUS=1.00f;
while(4){
printf("Select a currency type\n\n");
printf("1=European Euro 2=United Kingdom Pound 3=Japanese Yens 4=Canadian Dollars 5=Russian Rubles\n");
printf("Select the 4=Canadian Dollars currency type\n\n");

option=getch();
switch(option)
{
case '1':
printf("The selected currency type is the European Euro of %f equivalant to %f US  Dollar\n",fEUR,fUS);
break;
case '2':
printf("The selected currency type is the United Kingdom Pound of %f equivalant to %f US  Dollar\n",fGBP,fUS);
break;
case'3':
printf("The selected currency type is the Japanese Yens of %f equivalant to %f US  Dollar\n",fJPY,fUS);
break;
case'4':
printf("The selected currency type is the Canadian DOllars of %f equivalant to %f US  Dollar\n",fCAD,fUS);
break;
case '5':
printf("The selected currency type is the Russian Rubles of %f equivalant to %f US  Dollar\n",fRUR,fUS);
break;
case '0':
printf("exiting...\n");
return (0);
break;
default:
printf("The selected currency types 1,2,3,5 are invalid\n");
break;
printf("Number 4 Canadian Dollars has been selected\n\n");
}
}
getch();
return 0;
}

0

Commented:
Well, I get the following output:

Select a currency type

1=European Euro 2=United Kingdom Pound 3=Japanese Yens 4=Canadian Dollars 5=Russ
ian Rubles
Select the 4=Canadian Dollars currency type

The selected currency type is the Canadian DOllars of 1.317510 equivalant to 1.0
00000 US  Dollar

and that's what you wanted...
0

Commented:
Or, do you want to see what the user entered also? Then, add

option=getch();
printf("You entered %c\n", option);
0

Author Commented:
Yes that is what I want :-) but I do not get that printout"The selected currency type is the Canadian DOllars of 1.317510 equivalant to 1.0
00000 US  Dollar"
/*Select a currency conversion type by code number 8/11/04*/
#include <stdio.h>
int main(void)
{

char option;
EUR=1;
GBP=2;
JPY=3;
RUR=5;

fEUR=0.829643f;
fGBP=0.548242f;
fJPY=110.631f;
fRUR=29.1800f;
fUS=1.00f;
while(4){
printf("Select a currency type\n\n");
printf("1=European Euro 2=United Kingdom Pound 3=Japanese Yens 4=Canadian Dollars 5=Russian Rubles\n");
printf("Select the 4=Canadian Dollars currency type\n\n");

option=getch();
switch(option)
{
case '1':
printf("The selected currency type is the European Euro of %f equivalant to %f US  Dollar\n",fEUR,fUS);
break;
case '2':
printf("The selected currency type is the United Kingdom Pound of %f equivalant to %f US  Dollar\n",fGBP,fUS);
break;
case'3':
printf("The selected currency type is the Japanese Yens of %f equivalant to %f US  Dollar\n",fJPY,fUS);
break;
case'4':
printf("The selected currency type is the Canadian Dollars of %f equivalant to %f US  Dollar\n",fCAD,fUS);
break;
case '5':
printf("The selected currency type is the Russian Rubles of %f equivalant to %f US  Dollar\n",fRUR,fUS);
break;
case '0':
printf("exiting...\n");
return (0);
break;
default:
printf("The selected currency types 1,2,3,5 are invalid\n");
break;
printf("Number 4 Canadian Dollars has been selected\n\n");
}
}
getch();
return 0;
}

0

Commented:
You are not using the code I posted above, that's why.

BTW, why are you using

while(4){

?
0

Author Commented:
I thought that I had to use the 4 as the selected number. I changed it to 1 and it still will not print out that line. All of the code is the same as yours?
/*Select a currency conversion type by code number 8/11/04*/
#include <stdio.h>
int main(void)
{

char option;
EUR=1;
GBP=2;
JPY=3;
RUR=5;

fEUR=0.829643f;
fGBP=0.548242f;
fJPY=110.631f;
fRUR=29.1800f;
fUS=1.00f;
while(1){
printf("Select a currency type\n\n");
printf("1=European Euro 2=United Kingdom Pound 3=Japanese Yens 4=Canadian Dollars 5=Russian Rubles\n");
printf("Select the 4=Canadian Dollars currency type\n\n");

option=getch();
switch(option)
{
case '1':
printf("The selected currency type is the European Euro of %f equivalant to %f US  Dollar\n",fEUR,fUS);
break;
case '2':
printf("The selected currency type is the United Kingdom Pound of %f equivalant to %f US  Dollar\n",fGBP,fUS);
break;
case'3':
printf("The selected currency type is the Japanese Yens of %f equivalant to %f US  Dollar\n",fJPY,fUS);
break;
case'4':
printf("The selected currency type is the Canadian DOllars of %f equivalant to %f US  Dollar\n",fCAD,fUS);
break;
case '5':
printf("The selected currency type is the Russian Rubles of %f equivalant to %f US  Dollar\n",fRUR,fUS);
break;
case '0':
printf("exiting...\n");
return (0);
break;
default:
printf("The selected currency types 1,2,3,5 are invalid\n");
break;
printf("Number 4 Canadian Dollars has been selected\n\n");
}
}
getch();
return 0;
}

0

Commented:
Hm, I just compiled your very code and it prints:

C:\tmp\cc>cconv
Select a currency type

1=European Euro 2=United Kingdom Pound 3=Japanese Yens 4=Canadian Dollars 5=Russ
ian Rubles
Select the 4=Canadian Dollars currency type

The selected currency type is the Canadian DOllars of 1.317510 equivalant to 1.0
00000 US  Dollar
Select a currency type

1=European Euro 2=United Kingdom Pound 3=Japanese Yens 4=Canadian Dollars 5=Russ
ian Rubles
Select the 4=Canadian Dollars currency type
0

Author Commented:
For some reason it is only printing those same first three lines on my Miracle C complier. Tried to use scanf but am unsure as to where to put it. Thanks

/*Select a currency conversion type by code number 8/11/04*/
#include <stdio.h>
int main(void)
{

char option;
EUR=1;
GBP=2;
JPY=3;
RUR=5;

fEUR=0.829643f;
fGBP=0.548242f;
fJPY=110.631f;
fRUR=29.1800f;
fUS=1.00f;
while(1){
printf("Select a currency type\n\n");
printf("1=European Euro 2=United Kingdom Pound 3=Japanese Yens 4=Canadian Dollars 5=Russian Rubles\n");
printf("Select the 4=Canadian Dollars currency type\n\n");

option=getch();
switch(option)
{
case '1':
printf("The selected currency type is the European Euro of %f equivalent to %f US  Dollar\n",fEUR,fUS);
break;
case '2':
printf("The selected currency type is the United Kingdom Pound of %f equivalent to %f US  Dollar\n",fGBP,fUS);
break;
case'3':
printf("The selected currency type is the Japanese Yens of %f equivalent to %f US  Dollar\n",fJPY,fUS);
break;
case'4':
printf("The selected currency type is the Canadian Dollars of %f equivalent to %f US  Dollar\n",fCAD,fUS);
break;
case '5':
printf("The selected currency type is the Russian Rubles of %f equivalent to %f US  Dollar\n",fRUR,fUS);
break;
case '0':
printf("exiting...\n");
return (0);
break;
default:
scanf("%c", &option);
option=getch();
printf("You entered %c\n", option);
printf("The selected currency types 1,2,3,5 are invalid\n");
break;
printf("Number 4 Canadian Dollars has been selected\n\n");
}
}
getch();
return 0;
}

0

Commented:
Err, a stupid remark - have you tried to press the "4" on your keyboard? This is somehow a requirement... *duck*
0

Author Commented:
What do you mean? If I press the four it just adds in fours in the program where the curser is. Sorry for my ignorance but I know nothing :-(
0

Commented:
Well, pressing the "4" when running your application is supposed to do the "menu selection" and display the above text (sorry if that sounds stupid)
0

Author Commented:
Your a geninus :-) and the best of the best. Is there a way to assign triple extra extra points? You do work hard for them.  :-) The wierd thing though is now it prints out Select a currency type and 1=European Euro 2=United Kingdom Pound 3=Japanese Yens 4=Canadian Dollars 5=Russian Rubles twice Oh my!
0

Commented:
>>The wierd thing though is now it prints out Select a currency type and 1=European Euro 2=United Kingdom Pound
>>3=Japanese Yens 4=Canadian Dollars 5=Russian Rubles twice Oh my!

That's the loop - if you don't want that, make it read

/*Select a currency conversion type by code number 8/11/04*/
#include <stdio.h>
int main(void)
{

char option;
EUR=1;
GBP=2;
JPY=3;
RUR=5;

fEUR=0.829643f;
fGBP=0.548242f;
fJPY=110.631f;
fRUR=29.1800f;
fUS=1.00f;
printf("Select a currency type\n\n");
printf("1=European Euro 2=United Kingdom Pound 3=Japanese Yens 4=Canadian Dollars 5=Russian Rubles\n");
printf("Select the 4=Canadian Dollars currency type\n\n");

while(1){

option=getch();
switch(option)
{
case '1':
printf("The selected currency type is the European Euro of %f equivalent to %f US  Dollar\n",fEUR,fUS);
break;
case '2':
printf("The selected currency type is the United Kingdom Pound of %f equivalent to %f US  Dollar\n",fGBP,fUS);
break;
case'3':
printf("The selected currency type is the Japanese Yens of %f equivalent to %f US  Dollar\n",fJPY,fUS);
break;
case'4':
printf("The selected currency type is the Canadian Dollars of %f equivalent to %f US  Dollar\n",fCAD,fUS);
break;
case '5':
printf("The selected currency type is the Russian Rubles of %f equivalent to %f US  Dollar\n",fRUR,fUS);
break;
case '0':
printf("exiting...\n");
return (0);
break;
default:
scanf("%c", &option);
option=getch();
printf("You entered %c\n", option);
printf("The selected currency types 1,2,3,5 are invalid\n");
break;
printf("Number 4 Canadian Dollars has been selected\n\n");
}
}
getch();
return 0;
}
0

Author Commented:
Thank you so much. I have learned so much from you today that I well carry it all with me for a life time. Your talents are amazing. Sincerest thanks Rebecca
0

Commented:
You're most welcome, but don't exaggerate :o)
0

Author Commented:
Hi again :-) Sorry to bother you but I was wondering if I only wanted to print out the 4 option as suggested in the program what are some ways to try and do that without selecting the other invalid options of 1,2,3,5? Thanks in advance
/**************************************************************************************************/
/*Select a currency conversion type by code number 8/11/04*/
#include <stdio.h>
int main(void)
{

char option;
EUR=1;
GBP=2;
JPY=3;
RUR=5;

fEUR=0.829643f;
fGBP=0.548242f;
fJPY=110.631f;
fRUR=29.1800f;
fUS=1.00f;

printf("Select a currency type\n\n");
printf("1=European Euro 2=United Kingdom Pound 3=Japanese Yens 4=Canadian Dollars 5=Russian Rubles\n");
printf("Select the 4=Canadian Dollars currency type\n\n");
while(1) {
option=getch();
switch(option)
{
case '1':
printf("The selected currency type is the European Euro of %f equivalent to %f US  Dollar\n",fEUR,fUS);
break;
case '2':
printf("The selected currency type is the United Kingdom Pound of %f equivalent to %f US  Dollar\n",fGBP,fUS);
break;
case'3':
printf("The selected currency type is the Japanese Yens of %f equivalent to %f US  Dollar\n",fJPY,fUS);
break;
case'4':
printf("The selected currency type is the Canadian Dollars of %f equivalent to %f US  Dollar\n",fCAD,fUS);
break;
case '5':
printf("The selected currency type is the Russian Rubles of %f equivalent to %f US  Dollar\n",fRUR,fUS);
break;
case '0':
printf("exiting...\n");
return (0);
break;
default:
scanf("%c", & option);
option=getch();
printf("You entered %c\n", option);
printf("The selected currency types 1,2,3,5 are invalid\n");
break;
printf("Number 4 Canadian Dollars has been selected\n\n");
}
}
getch();
return 0;
}

0

Commented:
Well, you could just use

option=255;
while ( ! (option == '4' || option == '0')) {
printf("enter your choice (must be '4'):");
option=getch();
}
0

Author Commented:
Like this? I get a parse error? I thought that it meant my brackets are placed wrong but I do not see how? I think that I still need the switch statement so I left it in for the switch? Thanks
/*Select a currency conversion type by code number 8/11/04*/
#include <stdio.h>
int main(void)
{

char option;
EUR=1;
GBP=2;
JPY=3;
RUR=5;

fEUR=0.829643f;
fGBP=0.548242f;
fJPY=110.631f;
fRUR=29.1800f;
fUS=1.00f;

printf("Select a currency type\n\n");
printf("1=European Euro 2=United Kingdom Pound 3=Japanese Yens 4=Canadian Dollars 5=Russian Rubles\n");
printf("Select the 4=Canadian Dollars currency type\n\n");
option=255;
while ( ! (option == '4' || option == '0')) {
printf("enter your choice (must be '4'):");
option=getch();
switch(option)

}
case '1':
printf("The selected currency type is the European Euro of %f equivalent to %f US  Dollar\n",fEUR,fUS);
break;
case '2':
printf("The selected currency type is the United Kingdom Pound of %f equivalent to %f US  Dollar\n",fGBP,fUS);
break;
case'3':
printf("The selected currency type is the Japanese Yens of %f equivalent to %f US  Dollar\n",fJPY,fUS);
break;
case'4':
printf("The selected currency type is the Canadian Dollars of %f equivalent to %f US  Dollar\n",fCAD,fUS);
break;
case '5':
printf("The selected currency type is the Russian Rubles of %f equivalent to %f US  Dollar\n",fRUR,fUS);
break;
case '0':
printf("exiting...\n");
return (0);
break;
default:
scanf("%c", & option);
option=getch();
printf("You entered %c\n", option);
printf("The selected currency types 1,2,3,5 are invalid\n");
break;
printf("Number 4 Canadian Dollars has been selected\n\n");
}
}
getch();
return 0;
}

0

Commented:
Not quite, more like

/**************************************************************************************************/
/*Select a currency conversion type by code number 8/11/04*/
#include <stdio.h>
int main(void)
{

char option;
EUR=1;
GBP=2;
JPY=3;
RUR=5;

fEUR=0.829643f;
fGBP=0.548242f;
fJPY=110.631f;
fRUR=29.1800f;
fUS=1.00f;

printf("Select a currency type\n\n");
printf("1=European Euro 2=United Kingdom Pound 3=Japanese Yens 4=Canadian Dollars 5=Russian Rubles\n");
printf("Select the 4=Canadian Dollars currency type\n\n");

while(1) {

option=255;
while ( ! (option == '4' || option == '0')) {
printf("enter your choice (must be '4'):\n");
option=getch();
}

switch(option)
{
case '1':
printf("The selected currency type is the European Euro of %f equivalent to %f US  Dollar\n",fEUR,fUS);
break;
case '2':
printf("The selected currency type is the United Kingdom Pound of %f equivalent to %f US  Dollar\n",fGBP,fUS);
break;
case'3':
printf("The selected currency type is the Japanese Yens of %f equivalent to %f US  Dollar\n",fJPY,fUS);
break;
case'4':
printf("The selected currency type is the Canadian Dollars of %f equivalent to %f US  Dollar\n",fCAD,fUS);
break;
case '5':
printf("The selected currency type is the Russian Rubles of %f equivalent to %f US  Dollar\n",fRUR,fUS);
break;
case '0':
printf("exiting...\n");
return (0);
break;
default:
scanf("%c", & option);
option=getch();
printf("You entered %c\n", option);
printf("The selected currency types 1,2,3,5 are invalid\n");
break;
printf("Number 4 Canadian Dollars has been selected\n\n");
}
}
getch();
return 0;
}
0

Author Commented:
Oh I left out the while (1) as I thought that it would not be necessary. I was wondering why does the first while choice have to be 1? Is there a specific purpose for the 1? I understand now that the option is what ever you assign it so the 255 is just a randomly picked number. If I am right here than I can say see I am learning :-) I am going to have to sign up for life :-) Thanks
0

Author Commented:
Thannks and have a great day.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.