Thread: I am BRAND new to this, so please go easy on me

  1. #1
    Registered User
    Join Date
    Mar 2006
    Posts
    15

    I am BRAND new to this, so please go easy on me

    I am working on the all-knowing currency conversion program. It works, and I'm fairly happy with it - except for error checking. It doesn't do so well. I'm trying to use the isdigit function to ensure that the user types in an integer for the menu selection rather than a letter, but I can't quite seem to get it straight.

    This is what I have...

    Code:
    //Currency Conversion Program
    //Written by ***********, University of Phoenix
    //Version 2 3/26/2006
    
    #include <stdio.h>
    #include <system.h>
    #include <stdlib.h>
    #include <ctype.h>
    
    //global variable declarations and initialization with foreign exchange rates from <http://www.xe.com/ucc.convert.cgi> as of 3/19/2006
    //these global variables are to remain constant throughout use in the program
    float f_const_USD = 1.00;	//1.00 USD = 1.00 United States Dollar		 	
    float f_const_GBP = 0.569280;	//1.00 USD = 0.569280 United Kingdom Pounds
    float f_const_CAD = 1.15940; 	//1.00 USD = 1.15940 Canada Dollars
    float f_const_MXN = 10.7010; 	//1.00 USD = 10.7010 Mexico Pesos
    float f_const_JPY = 115.860; 	//1.00 USD = 115.860 Japan Yen
    float f_const_HKD = 7.75760;	//1.00 USD = 7.75760 Hong Kong Dollars
    
    main()  //Main Program for Currency Conversion
    
    {
    	//The following f_input variable is for storing the USD input from the user, declared initially as '0'
    	float f_input_USD = 0.00;  
    	//The following f_result variables are for storing calculations within the program declared initially as '0'
    	float f_result_USD = 0.00;	
    	float f_result_GBP = 0.00;
    	float f_result_CAD = 0.00;
    	float f_result_MXN = 0.00;
    	float f_result_JPY = 0.00;
    	float f_result_HKD = 0.00;
    	//variable declaration for menu input, default is '0'
    	int i_menu_choice = 0;
    	
    	while (i_menu_choice <6)
    	{
    		i_menu_choice = 0;
    		//create menu to choose currency conversion type
    		printf("\n\tCurrency Conversion\n");  //Title of Program
    		printf("\n1\tConvert US Dollars to United Kingdom Pounds");
    		printf("\n2\tConvert US Dollars to Canadian Dollars");
    		printf("\n3\tConvert US Dollars to Mexican Pesos");
    		printf("\n4\tConvert US Dollars to Japanese Yen");
    		printf("\n5\tConvert US Dollars to Hong Kong Dollars");
    		printf("\n6\tExit Currency Conversion Program\n\n");
    		//Accept input for menu selection
    		printf("Please make your selection now: ");
    		scanf("%d", &i_menu_choice);  
    	
    	//switch structure for menu selection
    	switch (i_menu_choice)
    	{
    		case 1:
    			printf("\nYou Selected Conversion from US Dollars to United Kingdom Pounds.");
    			printf("\nPlease Enter the Amount in x.xx US Dollars to Convert.\n$");
    			scanf("%f", &f_input_USD);  //get USD input from User for GBP conversion
    			break;
    		case 2:
    			printf("\nYou Selected Conversion from US Dollars to Canadian Dollars.");
    			printf("\nPlease Enter the Amount in x.xx US Dollars to Convert.\n$");
    			scanf("%f", &f_input_USD);  //get USD input from User for CAD conversion
    			break;
    		case 3:
    			printf("\nYou Selected Conversion from US Dollars to Mexican Pesos.");
    			printf("\nPlease Enter the Amount in x.xx US Dollars to Convert.\n$");
    			scanf("%f", &f_input_USD);  //get USD input from User for MXN conversion
    			break;
    		case 4:
    			printf("\nYou Selected Conversion from US Dollars to Japanese Yen.");
    			printf("\nPlease Enter the Amount in x.xx US Dollars to Convert.\n$");
    			scanf("%f", &f_input_USD);  //get USD input from User for JPY conversion
    			break;
    		case 5:
    			printf("\nYou Selected Conversion from US Dollars to Hong Kong Dollars.");
    			printf("\nPlease Enter the Amount in x.xx US Dollars to Convert.\n$");
    			scanf("%f", &f_input_USD);  //get USD input from User for HKD conversion
    			break;
    		case 6:
    			return 0;  //end program
    		default:
    			printf("\nYou Have Made and Invalid Selection.  Please Try Again.\n\n\n");
    			scanf("%d", &i_menu_choice);
    						
    	} //end switch
    	
    	//begin if structure for calculations
    	if (isdigit (i_menu_choice))
    	{
    		if (i_menu_choice == 1)
    		{
    			f_result_GBP = f_input_USD * f_const_GBP;
    			printf("\n$%.2f US Dollars is equal to ", f_input_USD);
    			printf("%.2f United Kingdom Pounds.\n\n", f_result_GBP);
    		}  //end if
    		else if	(i_menu_choice == 2)
    		{
    			f_result_CAD = f_input_USD * f_const_CAD;
    			printf("\n$%.2f US Dollars is equal to ", f_input_USD);
    			printf("%.2f Canadian Dollars.\n\n", f_result_CAD);
    		} //end else if
    		else if (i_menu_choice == 3)
    		{
    			f_result_MXN = f_input_USD * f_const_MXN;
    			printf("\n$%.2f US Dollars is equal to ", f_input_USD);
    			printf("%.2f Mexican Pesos.\n\n", f_result_MXN);
    		}  //end if
    		else if (i_menu_choice == 4)
    		{
    			f_result_JPY = f_input_USD * f_const_JPY;
    			printf("\n$%.2f US Dollars is equal to ", f_input_USD);
    			printf("%.2f Japanese Yen.\n\n", f_result_JPY);
    		}  //end if
    		else if (i_menu_choice == 5)
    		{
    			f_result_HKD = f_input_USD * f_const_HKD;
    			printf("\n$%.2f US Dollars is equal to ", f_input_USD);
    			printf("%.2f Hong Kong Dollars.\n\n", f_result_HKD);
    		}  //end if structure for calculations
    	} //end isdigit if structure
    	else
    	{
    		printf("\nThat is not a valid choice.  Please try again.");
    		getchar();
    	}
    	
    //printf("\n%d Was Your Menu Selection.\n\n", i_menu_choice);  //This line was here simply for error checking
    
    }  //end of while
    }  //end main program

  2. #2
    Registered User
    Join Date
    Feb 2006
    Posts
    20
    first of all global vars arent much of a use here , if you want to use them
    use the const therm to make them constant so nobody can change them
    you can also use #define and use the preprocessor

    please use void main(void) , ansi c would be int main(void) but then you have
    to return something , this is a nicer way to code and some compiler might want
    to whine about not declaring your main that well

    your choise is a letter (its a digit but the isdigit() fct check with charachters i think)
    im not sure but i think you should rather use a char for this. Anyhow
    1 != '1' because ascii is something higher , this might give you the error

    dunno of this might help
    Last edited by Narcose; 03-27-2006 at 11:15 AM.

  3. #3
    Registered User
    Join Date
    Mar 2006
    Posts
    15
    Unfortunately I have to use the Miracle C compiler for this course and the const float does not work. This is really the only way to do it (trust me, I've tried everything).

    How would you use the #define macro? Unfortunately we're not quite that far in the course yet...

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    > Unfortunately I have to use the Miracle C compiler for this course and the const float does not work
    Unfortunately, you're hosed then, and your tutor is a moron.

    Miracle C is a ........-poor compiler that barely deserves the name of "compiler".

    Any course which mandates this as your compiler simply isn't worth the trouble it's going to cause you when you get to use a real compiler.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  5. #5
    Registered User
    Join Date
    Jan 2006
    Posts
    36
    #define works like this and comes after your #includes
    Code:
    #define USD 1.00;	   //1.00 USD = 1.00 United States Dollar		 	
    #define GBP 0.569280;	//1.00 USD = 0.569280 United Kingdom Pounds
    #define CAD 1.15940; 	//1.00 USD = 1.15940 Canada Dollars
    #define MXN 10.7010; 	//1.00 USD = 10.7010 Mexico Pesos
    #define JPY 115.860; 	  //1.00 USD = 115.860 Japan Yen
    #define HKD 7.75760;	//1.00 USD = 7.75760 Hong Kong Dollars

  6. #6
    Registered User eth0's Avatar
    Join Date
    Dec 2003
    Posts
    164
    Quote Originally Posted by Narcose
    please use void main(void)
    You do realise you can be banned for such blasphemy

    christianne, how about simplifiying the code a little bit.

    Here is the same program, using char's to store the input instead of int's.
    All the error checking is done in the while loop

    I haven't tested this as I've just quickly edited what you had, but it should work on a C99 complaint compiler.

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <ctype.h>
    
    #define USD 1.00;	    //1.00 USD = 1.00 United States Dollar		 	
    #define GBP 0.569280;   //1.00 USD = 0.569280 United Kingdom Pounds
    #define CAD 1.15940; 	//1.00 USD = 1.15940 Canada Dollars
    #define MXN 10.7010; 	//1.00 USD = 10.7010 Mexico Pesos
    #define JPY 115.860; 	//1.00 USD = 115.860 Japan Yen
    #define HKD 7.75760;    //1.00 USD = 7.75760 Hong Kong Dollars
    
    int main()  //Main Program for Currency Conversion
    {
    	//The following f_input variable is for storing the USD input from the user, declared initially as '0'
    	float f_input_USD = 0.00;  
    	//The following f_result variables are for storing calculations within the program declared initially as '0'
    	float f_result_USD = 0.00;	
    	float f_result_GBP = 0.00;
    	float f_result_CAD = 0.00;
    	float f_result_MXN = 0.00;
    	float f_result_JPY = 0.00;
    	float f_result_HKD = 0.00;
    	char i_menu_choice;
    	//variable declaration for menu input, default is '0'
    	
    	do
    	{
    		//create menu to choose currency conversion type
    		printf("\n\tCurrency Conversion\n");  //Title of Program
    		printf("\n1\tConvert US Dollars to United Kingdom Pounds");
    		printf("\n2\tConvert US Dollars to Canadian Dollars");
    		printf("\n3\tConvert US Dollars to Mexican Pesos");
    		printf("\n4\tConvert US Dollars to Japanese Yen");
    		printf("\n5\tConvert US Dollars to Hong Kong Dollars");
    		printf("\n6\tExit Currency Conversion Program\n\n");
    		//Accept input for menu selection
    		printf("Please make your selection now: ");
    		i_menu_choice = getchar();
        } while (!isdigit(i_menu_choice) || (i_menu_choice < '1') || (i_menu_choice > '6'));
    	
    	//switch structure for menu selection
    	switch (i_menu_choice)
    	{
    		case '1':
    			printf("\nYou Selected Conversion from US Dollars to United Kingdom Pounds.");
    			printf("\nPlease Enter the Amount in x.xx US Dollars to Convert.\n$");
    			scanf("%f", &f_input_USD);  //get USD input from User for GBP conversion
    
    			f_result_GBP = f_input_USD * GBP;
    			printf("\n$%.2f US Dollars is equal to ", f_input_USD);
    			printf("%.2f United Kingdom Pounds.\n\n", f_result_GBP);
    
    		break;
    
    		case '2':
    			printf("\nYou Selected Conversion from US Dollars to Canadian Dollars.");
    			printf("\nPlease Enter the Amount in x.xx US Dollars to Convert.\n$");
    			scanf("%f", &f_input_USD);  //get USD input from User for CAD conversion
    
    			f_result_CAD = f_input_USD * CAD;
    			printf("\n$%.2f US Dollars is equal to ", f_input_USD);
    			printf("%.2f Canadian Dollars.\n\n", f_result_CAD);
    
    		break;
    
    		case '3':
    			printf("\nYou Selected Conversion from US Dollars to Mexican Pesos.");
    			printf("\nPlease Enter the Amount in x.xx US Dollars to Convert.\n$");
    			scanf("%f", &f_input_USD);  //get USD input from User for MXN conversion
    
    			f_result_MXN = f_input_USD * MXN;
    			printf("\n$%.2f US Dollars is equal to ", f_input_USD);
    			printf("%.2f Mexican Pesos.\n\n", f_result_MXN);
    
    		break;
    
    		case '4':
    			printf("\nYou Selected Conversion from US Dollars to Japanese Yen.");
    			printf("\nPlease Enter the Amount in x.xx US Dollars to Convert.\n$");
    			scanf("%f", &f_input_USD);  //get USD input from User for JPY conversion
    
    			f_result_JPY = f_input_USD * JPY;
    			printf("\n$%.2f US Dollars is equal to ", f_input_USD);
    			printf("%.2f Japanese Yen.\n\n", f_result_JPY);
    
    		break;
    
    		case '5':
    			printf("\nYou Selected Conversion from US Dollars to Hong Kong Dollars.");
    			printf("\nPlease Enter the Amount in x.xx US Dollars to Convert.\n$");
    			scanf("%f", &f_input_USD);  //get USD input from User for HKD conversion
    
    			f_result_HKD = f_input_USD * HKD;
    			printf("\n$%.2f US Dollars is equal to ", f_input_USD);
    			printf("%.2f Hong Kong Dollars.\n\n", f_result_HKD);
    
    		break;
    
    		case '6':
    			return 0;  //end program
    	
    	} //end switch
    }  //end main program
    Open source isn't a matter of life or death......
    .......its much more important than that!!


    SuSE Linux - GCC 3.4.2
    XP Pro - Visual Studio 2005 TS, MinGW 3.4.2

  7. #7
    Registered User
    Join Date
    Mar 2006
    Posts
    15
    Oh thank you - and I agree, I do most of my programming in Linux and use the gcc compiler, then tweak it backwards to fit the Miracle C. You're all right... it's a pretty useless compiler. Apparantly UofPhx used to use something much better, but the students whined about having to spend the money. My thoughts, it's totally worth the cost to 'actually' learn what you're doing.

    Thank you - I had recieved input that I should be using the getchar(), but I was lost on how to do it. Now I've got it.... thanks to all of you for your help!

  8. #8
    Registered User
    Join Date
    Mar 2006
    Posts
    15

    Wait a sec....

    Okay, now when I type in my float to perform the conversion, it quits???

    Code:
    //Currency Conversion Program
    //Written by ***********, University of Phoenix
    //Version 2 3/26/2006
    
    #include <stdio.h>
    #include <system.h>
    #include <stdlib.h>
    #include <ctype.h>
    
    //global variable declarations and initialization with foreign exchange rates from <http://www.xe.com/ucc.convert.cgi> as of 3/19/2006
    //these global variables are to remain constant throughout use in the program
    
    #define f_const_USD 1.00;	//1.00 USD = 1.00 United States Dollar		 	
    #define f_const_GBP 0.569280;	//1.00 USD = 0.569280 United Kingdom Pounds
    #define f_const_CAD 1.15940; 	//1.00 USD = 1.15940 Canada Dollars
    #define f_const_MXN 10.7010; 	//1.00 USD = 10.7010 Mexico Pesos
    #define f_const_JPY 115.860; 	//1.00 USD = 115.860 Japan Yen
    #define f_const_HKD 7.75760;	//1.00 USD = 7.75760 Hong Kong Dollars
    
    main(void)  //Main Program for Currency Conversion
     //Menu Choice Function
    {
    	//The following f_input variable is for storing the USD input from the user, declared initially as '0'
    	float f_input_USD = 0.00;  
    	//The following f_result variables are for storing calculations within the program declared initially as '0'
    	float f_result_USD = 0.00;	
    	float f_result_GBP = 0.00;
    	float f_result_CAD = 0.00;
    	float f_result_MXN = 0.00;
    	float f_result_JPY = 0.00;
    	float f_result_HKD = 0.00;
    	//variable declaration for menu input, default is '0'
    	int i_menu_choice = 0;
    		
    	do //Error Checking Loop Structure for Menu Selection
    	{
    		//create menu to choose currency conversion type
    		printf("\n\tCurrency Conversion\n");  //Title of Program
    		printf("\n1\tConvert US Dollars to United Kingdom Pounds");
    		printf("\n2\tConvert US Dollars to Canadian Dollars");
    		printf("\n3\tConvert US Dollars to Mexican Pesos");
    		printf("\n4\tConvert US Dollars to Japanese Yen");
    		printf("\n5\tConvert US Dollars to Hong Kong Dollars");
    		printf("\n6\tExit Currency Conversion Program\n\n");
    		//Accept input for menu selection
    		printf("Please make your selection now: ");
    		i_menu_choice = getchar();
    		
    	}
    	while (!isdigit(i_menu_choice) || (i_menu_choice , '1') && (i_menu_choice > '6'));
    	
    	//switch structure for menu selection
    	switch (i_menu_choice)
    	{
    		case '1':
    			printf("\nYou Selected Conversion from US Dollars to United Kingdom Pounds.");
    			printf("\nPlease Enter the Amount in x.xx US Dollars to Convert.\n$");
    			scanf("%f", &f_input_USD);  //get USD input from User for GBP conversion
    			break;
    		case '2':
    			printf("\nYou Selected Conversion from US Dollars to Canadian Dollars.");
    			printf("\nPlease Enter the Amount in x.xx US Dollars to Convert.\n$");
    			scanf("%f", &f_input_USD);  //get USD input from User for CAD conversion
    			break;
    		case '3':
    			printf("\nYou Selected Conversion from US Dollars to Mexican Pesos.");
    			printf("\nPlease Enter the Amount in x.xx US Dollars to Convert.\n$");
    			scanf("%f", &f_input_USD);  //get USD input from User for MXN conversion
    			break;
    		case '4':
    			printf("\nYou Selected Conversion from US Dollars to Japanese Yen.");
    			printf("\nPlease Enter the Amount in x.xx US Dollars to Convert.\n$");
    			scanf("%f", &f_input_USD);  //get USD input from User for JPY conversion
    			break;
    		case '5':
    			printf("\nYou Selected Conversion from US Dollars to Hong Kong Dollars.");
    			printf("\nPlease Enter the Amount in x.xx US Dollars to Convert.\n$");
    			scanf("%f", &f_input_USD);  //get USD input from User for HKD conversion
    			break;
    		case '6':
    			return 0;  //end program
    		default:
    			printf("\nYou Have Made and Invalid Selection.  Please Try Again.\n\n\n");
    			i_menu_choice = getchar();
    						
    	} //end switch
    	
    
    		if (i_menu_choice == '1')
    		{
    			f_result_GBP = f_input_USD * f_const_GBP;
    			printf("\n$%.2f US Dollars is equal to $", f_input_USD);
    			printf("%.2f United Kingdom Pounds.\n\n", f_result_GBP);
    		}  //end if
    		else if	(i_menu_choice == '2')
    		{
    			f_result_CAD = f_input_USD * f_const_CAD;
    			printf("\n$%.2f US Dollars is equal to $", f_input_USD);
    			printf("%.2f Canadian Dollars.\n\n", f_result_CAD);
    		} //end else if
    		else if (i_menu_choice == '3')
    		{
    			f_result_MXN = f_input_USD * f_const_MXN;
    			printf("\n$%.2f US Dollars is equal to $", f_input_USD);
    			printf("%.2f Mexican Pesos.\n\n", f_result_MXN);
    		}  //end if
    		else if (i_menu_choice == '4')
    		{
    			f_result_JPY = f_input_USD * f_const_JPY;
    			printf("\n$%.2f US Dollars is equal to $", f_input_USD);
    			printf("%.2f Japanese Yen.\n\n", f_result_JPY);
    		}  //end if
    		else if (i_menu_choice == '5')
    		{
    			f_result_HKD = f_input_USD * f_const_HKD;
    			printf("\n$%.2f US Dollars is equal to $", f_input_USD);
    			printf("%.2f Hong Kong Dollars.\n\n", f_result_HKD);
    		}  //end if structure for calculations
    
    	
    //printf("\n%d Was Your Menu Selection.\n\n", i_menu_choice);  //This line was here simply for error checking
    
    }  //end main program

  9. #9
    Registered User
    Join Date
    Mar 2006
    Posts
    15
    Don't I have to use some sort of continue function?

  10. #10
    Registered User
    Join Date
    Mar 2006
    Posts
    15
    Sorry, that was dumb.... here, but it still quits after entering the float for f_input_USD.

    I'm not asking you guys to do anything for me, please don't - but just show me where I'm going wrong. I've actually learned more in the past three hours than I did all weekend!

    Code:
    //Currency Conversion Program
    //Written by *********, University of Phoenix
    //Version 2 3/26/2006
    
    #include <stdio.h>
    #include <system.h>
    #include <stdlib.h>
    #include <ctype.h>
    
    //global variable declarations and initialization with foreign exchange rates from <http://www.xe.com/ucc.convert.cgi> as of 3/19/2006
    //these global variables are to remain constant throughout use in the program
    
    #define f_const_USD 1.00;	//1.00 USD = 1.00 United States Dollar		 	
    #define f_const_GBP 0.569280;	//1.00 USD = 0.569280 United Kingdom Pounds
    #define f_const_CAD 1.15940; 	//1.00 USD = 1.15940 Canada Dollars
    #define f_const_MXN 10.7010; 	//1.00 USD = 10.7010 Mexico Pesos
    #define f_const_JPY 115.860; 	//1.00 USD = 115.860 Japan Yen
    #define f_const_HKD 7.75760;	//1.00 USD = 7.75760 Hong Kong Dollars
    
    main(void)  //Main Program for Currency Conversion
     //Menu Choice Function
    {
    	//The following f_input variable is for storing the USD input from the user, declared initially as '0'
    	float f_input_USD = 0.00;  
    	//The following f_result variables are for storing calculations within the program declared initially as '0'
    	float f_result_USD = 0.00;	
    	float f_result_GBP = 0.00;
    	float f_result_CAD = 0.00;
    	float f_result_MXN = 0.00;
    	float f_result_JPY = 0.00;
    	float f_result_HKD = 0.00;
    	//variable declaration for menu input, default is '0'
    	int i_menu_choice = 0;
    		
    	do //Error Checking Loop Structure for Menu Selection
    	{
    		//create menu to choose currency conversion type
    		printf("\n\tCurrency Conversion\n");  //Title of Program
    		printf("\n1\tConvert US Dollars to United Kingdom Pounds");
    		printf("\n2\tConvert US Dollars to Canadian Dollars");
    		printf("\n3\tConvert US Dollars to Mexican Pesos");
    		printf("\n4\tConvert US Dollars to Japanese Yen");
    		printf("\n5\tConvert US Dollars to Hong Kong Dollars");
    		printf("\n6\tExit Currency Conversion Program\n\n");
    		//Accept input for menu selection
    		printf("Please make your selection now: ");
    		i_menu_choice = getchar();
    		
    	}
    	while (!isdigit(i_menu_choice) || (i_menu_choice , '1') && (i_menu_choice > '6'));
    	
    	//switch structure for menu selection
    	switch (i_menu_choice)
    	{
    		case '1':
    			printf("\nYou Selected Conversion from US Dollars to United Kingdom Pounds.");
    			printf("\nPlease Enter the Amount in x.xx US Dollars to Convert.\n$");
    			scanf("%f", &f_input_USD);  //get USD input from User for GBP conversion
    			f_result_GBP = f_input_USD * f_const_GBP;
    			printf("\n$%.2f US Dollars is equal to $", f_input_USD);
    			printf("%.2f United Kingdom Pounds.\n\n", f_result_GBP);
    			break;
    		case '2':
    			printf("\nYou Selected Conversion from US Dollars to Canadian Dollars.");
    			printf("\nPlease Enter the Amount in x.xx US Dollars to Convert.\n$");
    			scanf("%f", &f_input_USD);  //get USD input from User for CAD conversion
    			f_result_CAD = f_input_USD * f_const_CAD;
    			printf("\n$%.2f US Dollars is equal to $", f_input_USD);
    			printf("%.2f Canadian Dollars.\n\n", f_result_CAD);
    			break;
    		case '3':
    			printf("\nYou Selected Conversion from US Dollars to Mexican Pesos.");
    			printf("\nPlease Enter the Amount in x.xx US Dollars to Convert.\n$");
    			scanf("%f", &f_input_USD);  //get USD input from User for MXN conversion
    			f_result_MXN = f_input_USD * f_const_MXN;
    			printf("\n$%.2f US Dollars is equal to $", f_input_USD);
    			printf("%.2f Mexican Pesos.\n\n", f_result_MXN);
    			break;
    		case '4':
    			printf("\nYou Selected Conversion from US Dollars to Japanese Yen.");
    			printf("\nPlease Enter the Amount in x.xx US Dollars to Convert.\n$");
    			scanf("%f", &f_input_USD);  //get USD input from User for JPY conversion
    			f_result_JPY = f_input_USD * f_const_JPY;
    			printf("\n$%.2f US Dollars is equal to $", f_input_USD);
    			printf("%.2f Japanese Yen.\n\n", f_result_JPY);
    			break;
    		case '5':
    			printf("\nYou Selected Conversion from US Dollars to Hong Kong Dollars.");
    			printf("\nPlease Enter the Amount in x.xx US Dollars to Convert.\n$");
    			scanf("%f", &f_input_USD);  //get USD input from User for HKD conversion
    			f_result_HKD = f_input_USD * f_const_HKD;
    			printf("\n$%.2f US Dollars is equal to $", f_input_USD);
    			printf("%.2f Hong Kong Dollars.\n\n", f_result_HKD);
    			break;
    		case '6':
    			return 0;  //end program
    		default:
    			printf("\nYou Have Made and Invalid Selection.  Please Try Again.\n\n\n");
    			i_menu_choice = getchar();
    						
    	} //end switch
    	
    //printf("\n%d Was Your Menu Selection.\n\n", i_menu_choice);  //This line was here simply for error checking
    
    }  //end main program

  11. #11
    Registered User
    Join Date
    Jan 2002
    Location
    Vancouver
    Posts
    2,212
    Quote Originally Posted by christianne
    Apparantly UofPhx used to use something much better, but the students whined about having to spend the money. help!
    Let your tutor know about Dev-C++

    Also did you get taught this?
    Code:
    main()
    Because it's wrong. You should use:
    Code:
    int main(void)

  12. #12
    ---
    Join Date
    May 2004
    Posts
    1,379
    christianne: I just ran that code through my compiler (gcc) and it works fine. Are you still using Miracle C? I didn't test it for long but what I did test it didn't crash when inputting a float to f_input_USD

  13. #13
    Registered User eth0's Avatar
    Join Date
    Dec 2003
    Posts
    164
    Quote Originally Posted by Brian
    Let your tutor know about Dev-C++
    I think Code::Blocks has left Dev-C++ in it's tracks. It's starting to look and behave like VS now.
    However you'll need to get one of the nightly builds, the release version on their website is very old and crippled. They are due a release but keep holding it back for more new features....
    Open source isn't a matter of life or death......
    .......its much more important than that!!


    SuSE Linux - GCC 3.4.2
    XP Pro - Visual Studio 2005 TS, MinGW 3.4.2

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Seg fault in easy, easy code
    By lisa1901 in forum C++ Programming
    Replies: 11
    Last Post: 12-10-2007, 05:28 AM
  2. Java vs C to make an OS
    By WOP in forum Tech Board
    Replies: 59
    Last Post: 05-27-2007, 03:56 AM
  3. Easy question, (should be) easy answer... ;-)
    By Unregistered in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 06-12-2002, 09:36 PM
  4. Replies: 20
    Last Post: 05-25-2002, 07:14 PM
  5. EASY GUI development.. like with Qt?
    By rezonax in forum C++ Programming
    Replies: 2
    Last Post: 09-16-2001, 01:18 PM