• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 239
  • Last Modified:

C Programming - Calculation Display ??

I am struggling to figure out why this program is not calculating my amount and displaying it. Any help would be greatly appreciated:

/* Currency Conversion Program */
/* Program created for CSS-561 */
/* Program created for Week Five Assignment */
/* Assignment: Accept one input currency, then display in US Dollars */

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

/* Below are the abbreviations used for program */

/* Used the following website to find the conversion */
/* http://www.x-rates.com/calculator.html */

float CNY; /* Variable for Chinese Yuan */
int menuchoice; /* used to locate users input for conversion choice */



   printf("Currency Conversion\n"); /* Title of Program */
   printf("-------------------\n"); /* line of dashes for separation */  
   printf("\n"); /* insert a blank line */
   printf("Week Five Assignment CSS-561\n"); /* Assignment Week */
   printf("Jessie Cochran\n");  /* My Name */
   printf("\n"); /* insert a blank line */
   printf("Please input an amount to convert\n");
   printf("in Chinese Yuan\n"); /* Asking user to choose from a list of choices */
   printf("\n"); /* insert a blank line */

   printf("\n"); /* insert a blank line */

           
      switch(menuchoice) /* searches below cases for the correct case */
      {
      case 1:
            printf("Enter the value for Chinese Yuan Conversion:");
            scanf("%f",&CNY);
            
            printf("\n");/* insert a blank line */
            printf("\nThe US Dollar Equivalent is ");
            printf("%f", CNY/7.5948); /* Math calculation */
            
            break;
       }
   printf("\n");
         
         {
         printf("This is the end of my program");
         printf("\n");/* insert a blank line */
         printf("\n");/* insert a blank line */
         printf("I Hope you enjoyed using my conversion calculator");
         printf("\n");/* insert a blank line */
         printf("\n");/* insert a blank line */
         printf("Please hit Enter to close the program");
         }      

      getchar (); /* Add this line to stop the screen from closing immediately. */
      return 0;

}
0
JCochran1977
Asked:
JCochran1977
1 Solution
 
Infinity08Commented:
>>       switch(menuchoice) /* searches below cases for the correct case */

menuchoice does not contain any valid value, so the result of this switch statement is undefined. Since there's only one menu option anyway, you don't really need the switch, so just leave it out, and keep the body of the case 1 :


/* Currency Conversion Program */
/* Program created for CSS-561 */
/* Program created for Week Five Assignment */
/* Assignment: Accept one input currency, then display in US Dollars */

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

/* Below are the abbreviations used for program */

/* Used the following website to find the conversion */
/* http://www.x-rates.com/calculator.html */

float CNY; /* Variable for Chinese Yuan */



   printf("Currency Conversion\n"); /* Title of Program */
   printf("-------------------\n"); /* line of dashes for separation */  
   printf("\n"); /* insert a blank line */
   printf("Week Five Assignment CSS-561\n"); /* Assignment Week */
   printf("Jessie Cochran\n");  /* My Name */
   printf("\n"); /* insert a blank line */
   printf("Please input an amount to convert\n");
   printf("in Chinese Yuan\n"); /* Asking user to choose from a list of choices */
   printf("\n"); /* insert a blank line */

   printf("\n"); /* insert a blank line */

           
            printf("Enter the value for Chinese Yuan Conversion:");
            scanf("%f",&CNY);
           
            printf("\n");/* insert a blank line */
            printf("\nThe US Dollar Equivalent is ");
            printf("%f", CNY/7.5948); /* Math calculation */
           

   printf("\n");
         
         {
         printf("This is the end of my program");
         printf("\n");/* insert a blank line */
         printf("\n");/* insert a blank line */
         printf("I Hope you enjoyed using my conversion calculator");
         printf("\n");/* insert a blank line */
         printf("\n");/* insert a blank line */
         printf("Please hit Enter to close the program");
         }      

      getchar (); /* Add this line to stop the screen from closing immediately. */
      return 0;

}
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now