"Do You Wish To Continue?" Code Problems in C Programming

I am creating a program that will do currancy conversion. It works great, with one small problem. At the end of the currency conversion, the code is suppose to ask the user if they wish to continue with a simple Y/N inpput. If the user selects Y, then the program starts all over again. If the user slects N, then the program closes.

The code that I am using is:
printf("Do you wish to continue? ");
break;
Located at the end of each case.

I can not get the code to work. Can anyone offer any assistance to see where the fault is? Thanks so much!

Here is the complete code:

#include
int main()
{
int choice;
double Arate;
int currency;

//begin
printf("Currency Conversion
");
printf("Student Name
");
printf("
");//break to make the program look cleaner
printf("1. Honduras Lempira = $0.530200 USD
");//as of 6/18/05 from yahoo finance
printf("2. Kuwaiti Dinar =$3.4247 USD
");//as of 6/18/05 from yahoo finance
printf("3. Singapore Dollar = $0.599200 USD
");//as of 6/18/05 from yahoo finance
printf("4. Australian Dollar = $0.777900 USD
");//as of 6/18/05 from yahoo finance
printf("5. Canadian Dollar = $0.813500 USD
");//as of 6/18/05 from yahoo finance
printf("
");//break to make the program look cleaner
printf("Enter A Number From Above To Continue:"); //request currency number from user
scanf("%d", &choice); //allows a pause to view output

switch(choice)// do the conversions
{
case 1: // Honduras Lempira

currency=0;
printf("Enter an Honduras Lempira Dollar amount: $", currency); //requests currency amount from user
scanf("%d", &currency);
Arate = currency *0.530200; //calculates US dollar equivalent
printf("The US dollar equivalent is $%f
",Arate); //Prints US dollar equivalent amount
scanf("%d", &currency);
printf("
");//break to make the program look cleaner
printf("Do you wish to continue? ");
break;


case 2: // Kuwaiti Dinar

currency=0;
printf("Enter a Kuwaiti Dinar amount: $", currency); //requests foreign currency amount from user
scanf("%d", &currency);
Arate=currency*3.4247; //calculates US dollar equivalent
printf("The US dollar equivalent is $%f
",Arate); //Prints US dollar equivalent amount
scanf("%d", &currency);
printf("
");//break to make the program look cleaner
printf("Do you wish to continue? ");
break;
case 3: // Singapore Dollar


currency=0;
printf("Enter a Singapore Dollar amount: $", currency); //requests foreign currency amount from user
scanf("%d", &currency);
Arate=currency*0.599200; //calculates US dollar equivalent
printf("The US dollar equivalent is $%f
",Arate); //Prints US dollar equivalent amount
scanf("%d", &currency);
printf("
");//break to make the program look cleaner
printf("Do you wish to continue? ");
break;

case 4: // Australian Dollar
currency=0;
printf("Enter a Australian Dollar amount: $", currency); //requests foreign currency amount from user
scanf("%d", &currency);
Arate=currency*.777900; //calculates US dollar equivalent
printf("The US dollar equivalent is $%f
",Arate); //Prints US dollar equivalent amount
scanf("%d", &currency);
printf("
");//break to make the program look cleaner
printf("Do you wish to continue? ");
break;

case 5: // Canadian Dollar
currency=0;
printf("Enter a Canadian dollar amount: $", currency); //requests foreign currency amount from user
scanf("%d", &currency);
Arate=currency*0.813500; //calculates US dollar equivalent
printf("The US dollar equivalent is $%f
",Arate); //Prints US dollar equivalent amount
scanf("%d", &currency);
printf("
");//break to make the program look cleaner
printf("Do you wish to continue? ");
break;

}
return 0;

}





Comments

  • you're printing the text, but not stopping to get user input.
    [code]
    : printf("Do you wish to continue? ");
    int response = getch(); // see conio.h
    if( response == 'N' )
    : break;
    [/code]
    : I am creating a program that will do currancy conversion. It works great, with one small problem. At the end of the currency conversion, the code is suppose to ask the user if they wish to continue with a simple Y/N inpput. If the user selects Y, then the program starts all over again. If the user slects N, then the program closes.
    :
    : The code that I am using is:
    : printf("Do you wish to continue? ");
    : break;
    : Located at the end of each case.
    :
    : I can not get the code to work. Can anyone offer any assistance to see where the fault is? Thanks so much!
    :
    : Here is the complete code:
    :
    : #include
    : int main()
    : {
    : int choice;
    : double Arate;
    : int currency;
    :
    : //begin
    : printf("Currency Conversion
    ");
    : printf("Student Name
    ");
    : printf("
    ");//break to make the program look cleaner
    : printf("1. Honduras Lempira = $0.530200 USD
    ");//as of 6/18/05 from yahoo finance
    : printf("2. Kuwaiti Dinar =$3.4247 USD
    ");//as of 6/18/05 from yahoo finance
    : printf("3. Singapore Dollar = $0.599200 USD
    ");//as of 6/18/05 from yahoo finance
    : printf("4. Australian Dollar = $0.777900 USD
    ");//as of 6/18/05 from yahoo finance
    : printf("5. Canadian Dollar = $0.813500 USD
    ");//as of 6/18/05 from yahoo finance
    : printf("
    ");//break to make the program look cleaner
    : printf("Enter A Number From Above To Continue:"); //request currency number from user
    : scanf("%d", &choice); //allows a pause to view output
    :
    : switch(choice)// do the conversions
    : {
    : case 1: // Honduras Lempira
    :
    : currency=0;
    : printf("Enter an Honduras Lempira Dollar amount: $", currency); //requests currency amount from user
    : scanf("%d", &currency);
    : Arate = currency *0.530200; //calculates US dollar equivalent
    : printf("The US dollar equivalent is $%f
    ",Arate); //Prints US dollar equivalent amount
    : scanf("%d", &currency);
    : printf("
    ");//break to make the program look cleaner
    : printf("Do you wish to continue? ");
    : break;
    :
    :
    : case 2: // Kuwaiti Dinar
    :
    : currency=0;
    : printf("Enter a Kuwaiti Dinar amount: $", currency); //requests foreign currency amount from user
    : scanf("%d", &currency);
    : Arate=currency*3.4247; //calculates US dollar equivalent
    : printf("The US dollar equivalent is $%f
    ",Arate); //Prints US dollar equivalent amount
    : scanf("%d", &currency);
    : printf("
    ");//break to make the program look cleaner
    : printf("Do you wish to continue? ");
    : break;
    : case 3: // Singapore Dollar
    :
    :
    : currency=0;
    : printf("Enter a Singapore Dollar amount: $", currency); //requests foreign currency amount from user
    : scanf("%d", &currency);
    : Arate=currency*0.599200; //calculates US dollar equivalent
    : printf("The US dollar equivalent is $%f
    ",Arate); //Prints US dollar equivalent amount
    : scanf("%d", &currency);
    : printf("
    ");//break to make the program look cleaner
    : printf("Do you wish to continue? ");
    : break;
    :
    : case 4: // Australian Dollar
    : currency=0;
    : printf("Enter a Australian Dollar amount: $", currency); //requests foreign currency amount from user
    : scanf("%d", &currency);
    : Arate=currency*.777900; //calculates US dollar equivalent
    : printf("The US dollar equivalent is $%f
    ",Arate); //Prints US dollar equivalent amount
    : scanf("%d", &currency);
    : printf("
    ");//break to make the program look cleaner
    : printf("Do you wish to continue? ");
    : break;
    :
    : case 5: // Canadian Dollar
    : currency=0;
    : printf("Enter a Canadian dollar amount: $", currency); //requests foreign currency amount from user
    : scanf("%d", &currency);
    : Arate=currency*0.813500; //calculates US dollar equivalent
    : printf("The US dollar equivalent is $%f
    ",Arate); //Prints US dollar equivalent amount
    : scanf("%d", &currency);
    : printf("
    ");//break to make the program look cleaner
    : printf("Do you wish to continue? ");
    : break;
    :
    : }
    : return 0;
    :
    : }
    :
    :
    :
    :
    :
    :

  • Thanks for the response! Now I am geting an error:

    line 34: Parse Error, expecting `CASE' or `DEFAULT' or `'}''
    'int response = getch()'
    aborting compile

    What is causing this?



    : you're printing the text, but not stopping to get user input.
    : [code]
    : : printf("Do you wish to continue? ");
    : int response = getch(); // see conio.h
    : if( response == 'N' )
    : : break;
    : [/code]
    : : I am creating a program that will do currancy conversion. It works great, with one small problem. At the end of the currency conversion, the code is suppose to ask the user if they wish to continue with a simple Y/N inpput. If the user selects Y, then the program starts all over again. If the user slects N, then the program closes.
    : :
    : : The code that I am using is:
    : : printf("Do you wish to continue? ");
    : : break;
    : : Located at the end of each case.
    : :
    : : I can not get the code to work. Can anyone offer any assistance to see where the fault is? Thanks so much!
    : :
    : : Here is the complete code:
    : :
    : : #include
    : : int main()
    : : {
    : : int choice;
    : : double Arate;
    : : int currency;
    : :
    : : //begin
    : : printf("Currency Conversion
    ");
    : : printf("Student Name
    ");
    : : printf("
    ");//break to make the program look cleaner
    : : printf("1. Honduras Lempira = $0.530200 USD
    ");//as of 6/18/05 from yahoo finance
    : : printf("2. Kuwaiti Dinar =$3.4247 USD
    ");//as of 6/18/05 from yahoo finance
    : : printf("3. Singapore Dollar = $0.599200 USD
    ");//as of 6/18/05 from yahoo finance
    : : printf("4. Australian Dollar = $0.777900 USD
    ");//as of 6/18/05 from yahoo finance
    : : printf("5. Canadian Dollar = $0.813500 USD
    ");//as of 6/18/05 from yahoo finance
    : : printf("
    ");//break to make the program look cleaner
    : : printf("Enter A Number From Above To Continue:"); //request currency number from user
    : : scanf("%d", &choice); //allows a pause to view output
    : :
    : : switch(choice)// do the conversions
    : : {
    : : case 1: // Honduras Lempira
    : :
    : : currency=0;
    : : printf("Enter an Honduras Lempira Dollar amount: $", currency); //requests currency amount from user
    : : scanf("%d", &currency);
    : : Arate = currency *0.530200; //calculates US dollar equivalent
    : : printf("The US dollar equivalent is $%f
    ",Arate); //Prints US dollar equivalent amount
    : : scanf("%d", &currency);
    : : printf("
    ");//break to make the program look cleaner
    : : printf("Do you wish to continue? ");
    : : break;
    : :
    : :
    : : case 2: // Kuwaiti Dinar
    : :
    : : currency=0;
    : : printf("Enter a Kuwaiti Dinar amount: $", currency); //requests foreign currency amount from user
    : : scanf("%d", &currency);
    : : Arate=currency*3.4247; //calculates US dollar equivalent
    : : printf("The US dollar equivalent is $%f
    ",Arate); //Prints US dollar equivalent amount
    : : scanf("%d", &currency);
    : : printf("
    ");//break to make the program look cleaner
    : : printf("Do you wish to continue? ");
    : : break;
    : : case 3: // Singapore Dollar
    : :
    : :
    : : currency=0;
    : : printf("Enter a Singapore Dollar amount: $", currency); //requests foreign currency amount from user
    : : scanf("%d", &currency);
    : : Arate=currency*0.599200; //calculates US dollar equivalent
    : : printf("The US dollar equivalent is $%f
    ",Arate); //Prints US dollar equivalent amount
    : : scanf("%d", &currency);
    : : printf("
    ");//break to make the program look cleaner
    : : printf("Do you wish to continue? ");
    : : break;
    : :
    : : case 4: // Australian Dollar
    : : currency=0;
    : : printf("Enter a Australian Dollar amount: $", currency); //requests foreign currency amount from user
    : : scanf("%d", &currency);
    : : Arate=currency*.777900; //calculates US dollar equivalent
    : : printf("The US dollar equivalent is $%f
    ",Arate); //Prints US dollar equivalent amount
    : : scanf("%d", &currency);
    : : printf("
    ");//break to make the program look cleaner
    : : printf("Do you wish to continue? ");
    : : break;
    : :
    : : case 5: // Canadian Dollar
    : : currency=0;
    : : printf("Enter a Canadian dollar amount: $", currency); //requests foreign currency amount from user
    : : scanf("%d", &currency);
    : : Arate=currency*0.813500; //calculates US dollar equivalent
    : : printf("The US dollar equivalent is $%f
    ",Arate); //Prints US dollar equivalent amount
    : : scanf("%d", &currency);
    : : printf("
    ");//break to make the program look cleaner
    : : printf("Do you wish to continue? ");
    : : break;
    : :
    : : }
    : : return 0;
    : :
    : : }
    : :
    : :
    : :
    : :
    : :
    : :
    :
    :

  • : Thanks for the response! Now I am geting an error:
    :
    : line 34: Parse Error, expecting `CASE' or `DEFAULT' or `'}''
    : 'int response = getch()'
    : aborting compile
    :
    : What is causing this?
    :

    repost your code, but this time please put it in code tags.
  • Here is the code with the changes. Thanks again for your help!

    [code]#include
    int main()
    {
    int choice;
    double Arate;
    int currency;

    //begin
    printf("Currency Conversion
    ");
    printf("Student Name
    ");
    printf("
    ");//break to make the program look cleaner
    printf("1. Honduras Lempira = $0.530200 USD
    ");//as of 6/18/05 from yahoo finance
    printf("2. Kuwaiti Dinar =$3.4247 USD
    ");//as of 6/18/05 from yahoo finance
    printf("3. Singapore Dollar = $0.599200 USD
    ");//as of 6/18/05 from yahoo finance
    printf("4. Australian Dollar = $0.777900 USD
    ");//as of 6/18/05 from yahoo finance
    printf("5. Canadian Dollar = $0.813500 USD
    ");//as of 6/18/05 from yahoo finance
    printf("
    ");//break to make the program look cleaner
    printf("Enter A Number From Above To Continue:"); //request currency number from user
    scanf("%d", &choice); //allows a pause to view output

    switch(choice)// do the conversions
    {
    case 1: // Honduras Lempira

    currency=0;
    printf("Enter an Honduras Lempira Dollar amount: $", currency); //requests currency amount from user
    scanf("%d", &currency);
    Arate = currency *0.530200; //calculates US dollar equivalent
    printf("The US dollar equivalent is $%f
    ",Arate); //Prints US dollar equivalent amount
    scanf("%d", &currency);
    printf("
    ");//break to make the program look cleaner
    printf("Do you wish to continue? ");
    int response = getch(); // see conio.h
    if( response == 'N' )
    break;

    break;


    case 2: // Kuwaiti Dinar

    currency=0;
    printf("Enter a Kuwaiti Dinar amount: $", currency); //requests foreign currency amount from user
    scanf("%d", &currency);
    Arate=currency*3.4247; //calculates US dollar equivalent
    printf("The US dollar equivalent is $%f
    ",Arate); //Prints US dollar equivalent amount
    scanf("%d", &currency);
    printf("
    ");//break to make the program look cleaner
    printf("Do you wish to continue? ");
    break;
    case 3: // Singapore Dollar


    currency=0;
    printf("Enter a Singapore Dollar amount: $", currency); //requests foreign currency amount from user
    scanf("%d", &currency);
    Arate=currency*0.599200; //calculates US dollar equivalent
    printf("The US dollar equivalent is $%f
    ",Arate); //Prints US dollar equivalent amount
    scanf("%d", &currency);
    printf("
    ");//break to make the program look cleaner
    printf("Do you wish to continue? ");
    break;

    case 4: // Australian Dollar
    currency=0;
    printf("Enter a Australian Dollar amount: $", currency); //requests foreign currency amount from user
    scanf("%d", &currency);
    Arate=currency*.777900; //calculates US dollar equivalent
    printf("The US dollar equivalent is $%f
    ",Arate); //Prints US dollar equivalent amount
    scanf("%d", &currency);
    printf("
    ");//break to make the program look cleaner
    printf("Do you wish to continue? ");
    break;

    case 5: // Canadian Dollar
    currency=0;
    printf("Enter a Canadian dollar amount: $", currency); //requests foreign currency amount from user
    scanf("%d", &currency);
    Arate=currency*0.813500; //calculates US dollar equivalent
    printf("The US dollar equivalent is $%f
    ",Arate); //Prints US dollar equivalent amount
    scanf("%d", &currency);
    printf("
    ");//break to make the program look cleaner
    printf("Do you wish to continue? ");
    break;

    }
    return 0;

    }




    [/code]








    : : Thanks for the response! Now I am geting an error:
    : :
    : : line 34: Parse Error, expecting `CASE' or `DEFAULT' or `'}''
    : : 'int response = getch()'
    : : aborting compile
    : :
    : : What is causing this?
    : :
    :
    : repost your code, but this time please put it in code tags.
    :

  • [b][red]This message was edited by stober at 2005-6-18 19:0:54[/red][/b][hr]
    you can't (or shouldn't) just throw code in with no thought of what you are going! Is this a C program (*.c) or c++ (*.cpp)? If it is C, then you must declare variable response at the beginning of the function just like you did all the other variables. Then you have to decide what to do with the response. The question "do you wish to continue?" means what?? What is supposed to happen when you enter 'Y' and what do you do when you answer 'N'. Then rearrange the code to make it do both those actions. You may not be able to put that question in a case statement.

    : Here is the code with the changes. Thanks again for your help!
    :
    : [code]#include
    : int main()
    : {
    : int choice;
    : double Arate;
    : int currency;
    :
    : //begin
    : printf("Currency Conversion
    ");
    : printf("Student Name
    ");
    : printf("
    ");//break to make the program look cleaner
    : printf("1. Honduras Lempira = $0.530200 USD
    ");//as of 6/18/05 from yahoo finance
    : printf("2. Kuwaiti Dinar =$3.4247 USD
    ");//as of 6/18/05 from yahoo finance
    : printf("3. Singapore Dollar = $0.599200 USD
    ");//as of 6/18/05 from yahoo finance
    : printf("4. Australian Dollar = $0.777900 USD
    ");//as of 6/18/05 from yahoo finance
    : printf("5. Canadian Dollar = $0.813500 USD
    ");//as of 6/18/05 from yahoo finance
    : printf("
    ");//break to make the program look cleaner
    : printf("Enter A Number From Above To Continue:"); //request currency number from user
    : scanf("%d", &choice); //allows a pause to view output
    :
    : switch(choice)// do the conversions
    : {
    : case 1: // Honduras Lempira
    :
    : currency=0;
    : printf("Enter an Honduras Lempira Dollar amount: $", currency); //requests currency amount from user
    : scanf("%d", &currency);
    : Arate = currency *0.530200; //calculates US dollar equivalent
    : printf("The US dollar equivalent is $%f
    ",Arate); //Prints US dollar equivalent amount
    : scanf("%d", &currency);
    : printf("
    ");//break to make the program look cleaner
    : printf("Do you wish to continue? ");
    : int response = getch(); // see conio.h
    : if( response == 'N' )
    : break;
    :
    : break;
    :
    :
    : case 2: // Kuwaiti Dinar
    :
    : currency=0;
    : printf("Enter a Kuwaiti Dinar amount: $", currency); //requests foreign currency amount from user
    : scanf("%d", &currency);
    : Arate=currency*3.4247; //calculates US dollar equivalent
    : printf("The US dollar equivalent is $%f
    ",Arate); //Prints US dollar equivalent amount
    : scanf("%d", &currency);
    : printf("
    ");//break to make the program look cleaner
    : printf("Do you wish to continue? ");
    : break;
    : case 3: // Singapore Dollar
    :
    :
    : currency=0;
    : printf("Enter a Singapore Dollar amount: $", currency); //requests foreign currency amount from user
    : scanf("%d", &currency);
    : Arate=currency*0.599200; //calculates US dollar equivalent
    : printf("The US dollar equivalent is $%f
    ",Arate); //Prints US dollar equivalent amount
    : scanf("%d", &currency);
    : printf("
    ");//break to make the program look cleaner
    : printf("Do you wish to continue? ");
    : break;
    :
    : case 4: // Australian Dollar
    : currency=0;
    : printf("Enter a Australian Dollar amount: $", currency); //requests foreign currency amount from user
    : scanf("%d", &currency);
    : Arate=currency*.777900; //calculates US dollar equivalent
    : printf("The US dollar equivalent is $%f
    ",Arate); //Prints US dollar equivalent amount
    : scanf("%d", &currency);
    : printf("
    ");//break to make the program look cleaner
    : printf("Do you wish to continue? ");
    : break;
    :
    : case 5: // Canadian Dollar
    : currency=0;
    : printf("Enter a Canadian dollar amount: $", currency); //requests foreign currency amount from user
    : scanf("%d", &currency);
    : Arate=currency*0.813500; //calculates US dollar equivalent
    : printf("The US dollar equivalent is $%f
    ",Arate); //Prints US dollar equivalent amount
    : scanf("%d", &currency);
    : printf("
    ");//break to make the program look cleaner
    : printf("Do you wish to continue? ");
    : break;
    :
    : }
    : return 0;
    :
    : }
    :
    :
    :
    :
    : [/code]
    :
    :
    :
    :
    :
    :
    :
    :
    : : : Thanks for the response! Now I am geting an error:
    : : :
    : : : line 34: Parse Error, expecting `CASE' or `DEFAULT' or `'}''
    : : : 'int response = getch()'
    : : : aborting compile
    : : :
    : : : What is causing this?
    : : :
    : :
    : : repost your code, but this time please put it in code tags.
    : :
    :
    :



  • I thought I was clear on the code I was using and the process that I wanted to occur in my original post.

    Thanks for your help anyway...I will go to another website where hopefully people are a little more friendly when trying to help someone out. I guess I am just not as smart as you when it comes to this type of stuff.






    : [b][red]This message was edited by stober at 2005-6-18 19:0:54[/red][/b][hr]
    : you can't (or shouldn't) just throw code in with no thought of what you are going! Is this a C program (*.c) or c++ (*.cpp)? If it is C, then you must declare variable response at the beginning of the function just like you did all the other variables. Then you have to decide what to do with the response. The question "do you wish to continue?" means what?? What is supposed to happen when you enter 'Y' and what do you do when you answer 'N'. Then rearrange the code to make it do both those actions. You may not be able to put that question in a case statement.
    :
    : : Here is the code with the changes. Thanks again for your help!
    : :
    : : [code]#include
    : : int main()
    : : {
    : : int choice;
    : : double Arate;
    : : int currency;
    : :
    : : //begin
    : : printf("Currency Conversion
    ");
    : : printf("Student Name
    ");
    : : printf("
    ");//break to make the program look cleaner
    : : printf("1. Honduras Lempira = $0.530200 USD
    ");//as of 6/18/05 from yahoo finance
    : : printf("2. Kuwaiti Dinar =$3.4247 USD
    ");//as of 6/18/05 from yahoo finance
    : : printf("3. Singapore Dollar = $0.599200 USD
    ");//as of 6/18/05 from yahoo finance
    : : printf("4. Australian Dollar = $0.777900 USD
    ");//as of 6/18/05 from yahoo finance
    : : printf("5. Canadian Dollar = $0.813500 USD
    ");//as of 6/18/05 from yahoo finance
    : : printf("
    ");//break to make the program look cleaner
    : : printf("Enter A Number From Above To Continue:"); //request currency number from user
    : : scanf("%d", &choice); //allows a pause to view output
    : :
    : : switch(choice)// do the conversions
    : : {
    : : case 1: // Honduras Lempira
    : :
    : : currency=0;
    : : printf("Enter an Honduras Lempira Dollar amount: $", currency); //requests currency amount from user
    : : scanf("%d", &currency);
    : : Arate = currency *0.530200; //calculates US dollar equivalent
    : : printf("The US dollar equivalent is $%f
    ",Arate); //Prints US dollar equivalent amount
    : : scanf("%d", &currency);
    : : printf("
    ");//break to make the program look cleaner
    : : printf("Do you wish to continue? ");
    : : int response = getch(); // see conio.h
    : : if( response == 'N' )
    : : break;
    : :
    : : break;
    : :
    : :
    : : case 2: // Kuwaiti Dinar
    : :
    : : currency=0;
    : : printf("Enter a Kuwaiti Dinar amount: $", currency); //requests foreign currency amount from user
    : : scanf("%d", &currency);
    : : Arate=currency*3.4247; //calculates US dollar equivalent
    : : printf("The US dollar equivalent is $%f
    ",Arate); //Prints US dollar equivalent amount
    : : scanf("%d", &currency);
    : : printf("
    ");//break to make the program look cleaner
    : : printf("Do you wish to continue? ");
    : : break;
    : : case 3: // Singapore Dollar
    : :
    : :
    : : currency=0;
    : : printf("Enter a Singapore Dollar amount: $", currency); //requests foreign currency amount from user
    : : scanf("%d", &currency);
    : : Arate=currency*0.599200; //calculates US dollar equivalent
    : : printf("The US dollar equivalent is $%f
    ",Arate); //Prints US dollar equivalent amount
    : : scanf("%d", &currency);
    : : printf("
    ");//break to make the program look cleaner
    : : printf("Do you wish to continue? ");
    : : break;
    : :
    : : case 4: // Australian Dollar
    : : currency=0;
    : : printf("Enter a Australian Dollar amount: $", currency); //requests foreign currency amount from user
    : : scanf("%d", &currency);
    : : Arate=currency*.777900; //calculates US dollar equivalent
    : : printf("The US dollar equivalent is $%f
    ",Arate); //Prints US dollar equivalent amount
    : : scanf("%d", &currency);
    : : printf("
    ");//break to make the program look cleaner
    : : printf("Do you wish to continue? ");
    : : break;
    : :
    : : case 5: // Canadian Dollar
    : : currency=0;
    : : printf("Enter a Canadian dollar amount: $", currency); //requests foreign currency amount from user
    : : scanf("%d", &currency);
    : : Arate=currency*0.813500; //calculates US dollar equivalent
    : : printf("The US dollar equivalent is $%f
    ",Arate); //Prints US dollar equivalent amount
    : : scanf("%d", &currency);
    : : printf("
    ");//break to make the program look cleaner
    : : printf("Do you wish to continue? ");
    : : break;
    : :
    : : }
    : : return 0;
    : :
    : : }
    : :
    : :
    : :
    : :
    : : [/code]
    : :
    : :
    : :
    : :
    : :
    : :
    : :
    : :
    : : : : Thanks for the response! Now I am geting an error:
    : : : :
    : : : : line 34: Parse Error, expecting `CASE' or `DEFAULT' or `'}''
    : : : : 'int response = getch()'
    : : : : aborting compile
    : : : :
    : : : : What is causing this?
    : : : :
    : : :
    : : : repost your code, but this time please put it in code tags.
    : : :
    : :
    : :
    :
    :
    :
    :

  • : Here is the code with the changes. Thanks again for your help!
    :
    : [code]#include
    : int main()
    : {
    : int choice;
    : double Arate;
    : int currency;
    :
    : //begin
    : printf("Currency Conversion
    ");
    : printf("Student Name
    ");
    : printf("
    ");//break to make the program look cleaner
    : printf("1. Honduras Lempira = $0.530200 USD
    ");//as of 6/18/05 from yahoo finance
    : printf("2. Kuwaiti Dinar =$3.4247 USD
    ");//as of 6/18/05 from yahoo finance
    : printf("3. Singapore Dollar = $0.599200 USD
    ");//as of 6/18/05 from yahoo finance
    : printf("4. Australian Dollar = $0.777900 USD
    ");//as of 6/18/05 from yahoo finance
    : printf("5. Canadian Dollar = $0.813500 USD
    ");//as of 6/18/05 from yahoo finance
    : printf("
    ");//break to make the program look cleaner
    : printf("Enter A Number From Above To Continue:"); //request currency number from user
    : scanf("%d", &choice); //allows a pause to view output
    :
    : switch(choice)// do the conversions
    : {
    : case 1: // Honduras Lempira
    :
    : currency=0;
    : printf("Enter an Honduras Lempira Dollar amount: $", currency); //requests currency amount from user
    : scanf("%d", &currency);
    : Arate = currency *0.530200; //calculates US dollar equivalent
    : printf("The US dollar equivalent is $%f
    ",Arate); //Prints US dollar equivalent amount
    : scanf("%d", &currency);
    : printf("
    ");//break to make the program look cleaner
    : printf("Do you wish to continue? ");
    : int response = getch(); // see conio.h
    : if( response == 'N' )
    : break;
    :
    : break;
    :
    :
    : case 2: // Kuwaiti Dinar
    :
    : currency=0;
    : printf("Enter a Kuwaiti Dinar amount: $", currency); //requests foreign currency amount from user
    : scanf("%d", &currency);
    : Arate=currency*3.4247; //calculates US dollar equivalent
    : printf("The US dollar equivalent is $%f
    ",Arate); //Prints US dollar equivalent amount
    : scanf("%d", &currency);
    : printf("
    ");//break to make the program look cleaner
    : printf("Do you wish to continue? ");
    : break;
    : case 3: // Singapore Dollar
    :
    :
    : currency=0;
    : printf("Enter a Singapore Dollar amount: $", currency); //requests foreign currency amount from user
    : scanf("%d", &currency);
    : Arate=currency*0.599200; //calculates US dollar equivalent
    : printf("The US dollar equivalent is $%f
    ",Arate); //Prints US dollar equivalent amount
    : scanf("%d", &currency);
    : printf("
    ");//break to make the program look cleaner
    : printf("Do you wish to continue? ");
    : break;
    :
    : case 4: // Australian Dollar
    : currency=0;
    : printf("Enter a Australian Dollar amount: $", currency); //requests foreign currency amount from user
    : scanf("%d", &currency);
    : Arate=currency*.777900; //calculates US dollar equivalent
    : printf("The US dollar equivalent is $%f
    ",Arate); //Prints US dollar equivalent amount
    : scanf("%d", &currency);
    : printf("
    ");//break to make the program look cleaner
    : printf("Do you wish to continue? ");
    : break;
    :
    : case 5: // Canadian Dollar
    : currency=0;
    : printf("Enter a Canadian dollar amount: $", currency); //requests foreign currency amount from user
    : scanf("%d", &currency);
    : Arate=currency*0.813500; //calculates US dollar equivalent
    : printf("The US dollar equivalent is $%f
    ",Arate); //Prints US dollar equivalent amount
    : scanf("%d", &currency);
    : printf("
    ");//break to make the program look cleaner
    : printf("Do you wish to continue? ");
    : break;
    :
    : }
    : return 0;
    :
    : }
    :
    :
    :
    :
    : [/code]
    :
    :
    :
    :
    :
    :
    :
    :
    : : : Thanks for the response! Now I am geting an error:
    : : :
    : : : line 34: Parse Error, expecting `CASE' or `DEFAULT' or `'}''
    : : : 'int response = getch()'
    : : : aborting compile
    : : :
    : : : What is causing this?
    : : :
    : :
    : : repost your code, but this time please put it in code tags.
    : :
    :
    You need to put the switch statement into a loop that terminates when the user enters 'n'. Otherwise the program will terminate regardless of user input.
  • :
    : Thanks for your help anyway...I will go to another website where hopefully people are a little more friendly when trying to help someone out. I guess I am just not as smart as you when it comes to this type of stuff.
    :


    sorry if I sounded rude -- its not a matter of being "smarter" but of working harder to find the solution to a problem. Don't expect other people to do all your work. internet programming sites are nice, but there is no substitute for doing your own research, study and testing to find out how things work.
  • Try not to look at it as criticism, but as insight - stober
    knows his stuff; moreover, you're just as likely to find
    *harsh* words elsewhere if you don't follow the "requests"
    of the host forum.

    With C programming, you can only declare variables at the
    start of a code block... all you need is a set of
    brackets.
    [code]
    int main(void)
    {
    int var1;

    puts("...");

    {
    int var2;
    }
    }[/code]The thing you need to be aware of is the scope of the
    declared variable. From above, var1 is available throughout
    main, but var2 is local to that code block in which it's
    declared.

    As mentioned, you'll need a bottom test for your particular
    program, so response would need to be declared in main's scope.
    You might also think about using char types instead of int
    types since there is the potential for a user entering a
    character, which would throw your program into a fail
    state as it's currently coded using the ints and scanf.
    [code]char response;

    do
    {
    show menu
    get choice

    switch(choice)
    {
    ...
    }

    ask to continue or quit
    read in response

    }while(response != 'q');[/code]


    : I thought I was clear on the code I was using and the process that I wanted to occur in my original post.
    :
    : Thanks for your help anyway...I will go to another website where hopefully people are a little more friendly when trying to help someone out. I guess I am just not as smart as you when it comes to this type of stuff.
    :
    :
    :
    :
    :
    :
    : : [b][red]This message was edited by stober at 2005-6-18 19:0:54[/red][/b][hr]
    : : you can't (or shouldn't) just throw code in with no thought of what you are going! Is this a C program (*.c) or c++ (*.cpp)? If it is C, then you must declare variable response at the beginning of the function just like you did all the other variables. Then you have to decide what to do with the response. The question "do you wish to continue?" means what?? What is supposed to happen when you enter 'Y' and what do you do when you answer 'N'. Then rearrange the code to make it do both those actions. You may not be able to put that question in a case statement.
    : :
    : : : Here is the code with the changes. Thanks again for your help!
    : : :
    : : : [code]#include
    : : : int main()
    : : : {
    : : : int choice;
    : : : double Arate;
    : : : int currency;
    : : :
    : : : //begin
    : : : printf("Currency Conversion
    ");
    : : : printf("Student Name
    ");
    : : : printf("
    ");//break to make the program look cleaner
    : : : printf("1. Honduras Lempira = $0.530200 USD
    ");//as of 6/18/05 from yahoo finance
    : : : printf("2. Kuwaiti Dinar =$3.4247 USD
    ");//as of 6/18/05 from yahoo finance
    : : : printf("3. Singapore Dollar = $0.599200 USD
    ");//as of 6/18/05 from yahoo finance
    : : : printf("4. Australian Dollar = $0.777900 USD
    ");//as of 6/18/05 from yahoo finance
    : : : printf("5. Canadian Dollar = $0.813500 USD
    ");//as of 6/18/05 from yahoo finance
    : : : printf("
    ");//break to make the program look cleaner
    : : : printf("Enter A Number From Above To Continue:"); //request currency number from user
    : : : scanf("%d", &choice); //allows a pause to view output
    : : :
    : : : switch(choice)// do the conversions
    : : : {
    : : : case 1: // Honduras Lempira
    : : :
    : : : currency=0;
    : : : printf("Enter an Honduras Lempira Dollar amount: $", currency); //requests currency amount from user
    : : : scanf("%d", &currency);
    : : : Arate = currency *0.530200; //calculates US dollar equivalent
    : : : printf("The US dollar equivalent is $%f
    ",Arate); //Prints US dollar equivalent amount
    : : : scanf("%d", &currency);
    : : : printf("
    ");//break to make the program look cleaner
    : : : printf("Do you wish to continue? ");
    : : : int response = getch(); // see conio.h
    : : : if( response == 'N' )
    : : : break;
    : : :
    : : : break;
    : : :
    : : :
    : : : case 2: // Kuwaiti Dinar
    : : :
    : : : currency=0;
    : : : printf("Enter a Kuwaiti Dinar amount: $", currency); //requests foreign currency amount from user
    : : : scanf("%d", &currency);
    : : : Arate=currency*3.4247; //calculates US dollar equivalent
    : : : printf("The US dollar equivalent is $%f
    ",Arate); //Prints US dollar equivalent amount
    : : : scanf("%d", &currency);
    : : : printf("
    ");//break to make the program look cleaner
    : : : printf("Do you wish to continue? ");
    : : : break;
    : : : case 3: // Singapore Dollar
    : : :
    : : :
    : : : currency=0;
    : : : printf("Enter a Singapore Dollar amount: $", currency); //requests foreign currency amount from user
    : : : scanf("%d", &currency);
    : : : Arate=currency*0.599200; //calculates US dollar equivalent
    : : : printf("The US dollar equivalent is $%f
    ",Arate); //Prints US dollar equivalent amount
    : : : scanf("%d", &currency);
    : : : printf("
    ");//break to make the program look cleaner
    : : : printf("Do you wish to continue? ");
    : : : break;
    : : :
    : : : case 4: // Australian Dollar
    : : : currency=0;
    : : : printf("Enter a Australian Dollar amount: $", currency); //requests foreign currency amount from user
    : : : scanf("%d", &currency);
    : : : Arate=currency*.777900; //calculates US dollar equivalent
    : : : printf("The US dollar equivalent is $%f
    ",Arate); //Prints US dollar equivalent amount
    : : : scanf("%d", &currency);
    : : : printf("
    ");//break to make the program look cleaner
    : : : printf("Do you wish to continue? ");
    : : : break;
    : : :
    : : : case 5: // Canadian Dollar
    : : : currency=0;
    : : : printf("Enter a Canadian dollar amount: $", currency); //requests foreign currency amount from user
    : : : scanf("%d", &currency);
    : : : Arate=currency*0.813500; //calculates US dollar equivalent
    : : : printf("The US dollar equivalent is $%f
    ",Arate); //Prints US dollar equivalent amount
    : : : scanf("%d", &currency);
    : : : printf("
    ");//break to make the program look cleaner
    : : : printf("Do you wish to continue? ");
    : : : break;
    : : :
    : : : }
    : : : return 0;
    : : :
    : : : }
    : : :
    : : :
    : : :
    : : :
    : : : [/code]
    : : :
    : : :
    : : :
    : : :
    : : :
    : : :
    : : :
    : : :
    : : : : : Thanks for the response! Now I am geting an error:
    : : : : :
    : : : : : line 34: Parse Error, expecting `CASE' or `DEFAULT' or `'}''
    : : : : : 'int response = getch()'
    : : : : : aborting compile
    : : : : :
    : : : : : What is causing this?
    : : : : :
    : : : :
    : : : : repost your code, but this time please put it in code tags.
    : : : :
    : : :
    : : :
    : :
    : :
    : :
    : :
    :
    :
  • Thank you for the help and the examples! It makes sence now


    : Try not to look at it as criticism, but as insight - stober
    : knows his stuff; moreover, you're just as likely to find
    : *harsh* words elsewhere if you don't follow the "requests"
    : of the host forum.
    :
    : With C programming, you can only declare variables at the
    : start of a code block... all you need is a set of
    : brackets.
    : [code]
    : int main(void)
    : {
    : int var1;
    :
    : puts("...");
    :
    : {
    : int var2;
    : }
    : }[/code]The thing you need to be aware of is the scope of the
    : declared variable. From above, var1 is available throughout
    : main, but var2 is local to that code block in which it's
    : declared.
    :
    : As mentioned, you'll need a bottom test for your particular
    : program, so response would need to be declared in main's scope.
    : You might also think about using char types instead of int
    : types since there is the potential for a user entering a
    : character, which would throw your program into a fail
    : state as it's currently coded using the ints and scanf.
    : [code]char response;
    :
    : do
    : {
    : show menu
    : get choice
    :
    : switch(choice)
    : {
    : ...
    : }
    :
    : ask to continue or quit
    : read in response
    :
    : }while(response != 'q');[/code]
    :
    :
    : : I thought I was clear on the code I was using and the process that I wanted to occur in my original post.
    : :
    : : Thanks for your help anyway...I will go to another website where hopefully people are a little more friendly when trying to help someone out. I guess I am just not as smart as you when it comes to this type of stuff.
    : :
    : :
    : :
    : :
    : :
    : :
    : : : [b][red]This message was edited by stober at 2005-6-18 19:0:54[/red][/b][hr]
    : : : you can't (or shouldn't) just throw code in with no thought of what you are going! Is this a C program (*.c) or c++ (*.cpp)? If it is C, then you must declare variable response at the beginning of the function just like you did all the other variables. Then you have to decide what to do with the response. The question "do you wish to continue?" means what?? What is supposed to happen when you enter 'Y' and what do you do when you answer 'N'. Then rearrange the code to make it do both those actions. You may not be able to put that question in a case statement.
    : : :
    : : : : Here is the code with the changes. Thanks again for your help!
    : : : :
    : : : : [code]#include
    : : : : int main()
    : : : : {
    : : : : int choice;
    : : : : double Arate;
    : : : : int currency;
    : : : :
    : : : : //begin
    : : : : printf("Currency Conversion
    ");
    : : : : printf("Student Name
    ");
    : : : : printf("
    ");//break to make the program look cleaner
    : : : : printf("1. Honduras Lempira = $0.530200 USD
    ");//as of 6/18/05 from yahoo finance
    : : : : printf("2. Kuwaiti Dinar =$3.4247 USD
    ");//as of 6/18/05 from yahoo finance
    : : : : printf("3. Singapore Dollar = $0.599200 USD
    ");//as of 6/18/05 from yahoo finance
    : : : : printf("4. Australian Dollar = $0.777900 USD
    ");//as of 6/18/05 from yahoo finance
    : : : : printf("5. Canadian Dollar = $0.813500 USD
    ");//as of 6/18/05 from yahoo finance
    : : : : printf("
    ");//break to make the program look cleaner
    : : : : printf("Enter A Number From Above To Continue:"); //request currency number from user
    : : : : scanf("%d", &choice); //allows a pause to view output
    : : : :
    : : : : switch(choice)// do the conversions
    : : : : {
    : : : : case 1: // Honduras Lempira
    : : : :
    : : : : currency=0;
    : : : : printf("Enter an Honduras Lempira Dollar amount: $", currency); //requests currency amount from user
    : : : : scanf("%d", &currency);
    : : : : Arate = currency *0.530200; //calculates US dollar equivalent
    : : : : printf("The US dollar equivalent is $%f
    ",Arate); //Prints US dollar equivalent amount
    : : : : scanf("%d", &currency);
    : : : : printf("
    ");//break to make the program look cleaner
    : : : : printf("Do you wish to continue? ");
    : : : : int response = getch(); // see conio.h
    : : : : if( response == 'N' )
    : : : : break;
    : : : :
    : : : : break;
    : : : :
    : : : :
    : : : : case 2: // Kuwaiti Dinar
    : : : :
    : : : : currency=0;
    : : : : printf("Enter a Kuwaiti Dinar amount: $", currency); //requests foreign currency amount from user
    : : : : scanf("%d", &currency);
    : : : : Arate=currency*3.4247; //calculates US dollar equivalent
    : : : : printf("The US dollar equivalent is $%f
    ",Arate); //Prints US dollar equivalent amount
    : : : : scanf("%d", &currency);
    : : : : printf("
    ");//break to make the program look cleaner
    : : : : printf("Do you wish to continue? ");
    : : : : break;
    : : : : case 3: // Singapore Dollar
    : : : :
    : : : :
    : : : : currency=0;
    : : : : printf("Enter a Singapore Dollar amount: $", currency); //requests foreign currency amount from user
    : : : : scanf("%d", &currency);
    : : : : Arate=currency*0.599200; //calculates US dollar equivalent
    : : : : printf("The US dollar equivalent is $%f
    ",Arate); //Prints US dollar equivalent amount
    : : : : scanf("%d", &currency);
    : : : : printf("
    ");//break to make the program look cleaner
    : : : : printf("Do you wish to continue? ");
    : : : : break;
    : : : :
    : : : : case 4: // Australian Dollar
    : : : : currency=0;
    : : : : printf("Enter a Australian Dollar amount: $", currency); //requests foreign currency amount from user
    : : : : scanf("%d", &currency);
    : : : : Arate=currency*.777900; //calculates US dollar equivalent
    : : : : printf("The US dollar equivalent is $%f
    ",Arate); //Prints US dollar equivalent amount
    : : : : scanf("%d", &currency);
    : : : : printf("
    ");//break to make the program look cleaner
    : : : : printf("Do you wish to continue? ");
    : : : : break;
    : : : :
    : : : : case 5: // Canadian Dollar
    : : : : currency=0;
    : : : : printf("Enter a Canadian dollar amount: $", currency); //requests foreign currency amount from user
    : : : : scanf("%d", &currency);
    : : : : Arate=currency*0.813500; //calculates US dollar equivalent
    : : : : printf("The US dollar equivalent is $%f
    ",Arate); //Prints US dollar equivalent amount
    : : : : scanf("%d", &currency);
    : : : : printf("
    ");//break to make the program look cleaner
    : : : : printf("Do you wish to continue? ");
    : : : : break;
    : : : :
    : : : : }
    : : : : return 0;
    : : : :
    : : : : }
    : : : :
    : : : :
    : : : :
    : : : :
    : : : : [/code]
    : : : :
    : : : :
    : : : :
    : : : :
    : : : :
    : : : :
    : : : :
    : : : :
    : : : : : : Thanks for the response! Now I am geting an error:
    : : : : : :
    : : : : : : line 34: Parse Error, expecting `CASE' or `DEFAULT' or `'}''
    : : : : : : 'int response = getch()'
    : : : : : : aborting compile
    : : : : : :
    : : : : : : What is causing this?
    : : : : : :
    : : : : :
    : : : : : repost your code, but this time please put it in code tags.
    : : : : :
    : : : :
    : : : :
    : : :
    : : :
    : : :
    : : :
    : :
    : :
    :

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories