Thread: Please help, internal compiler error

  1. #1
    Cap
    Guest

    Unhappy Please help, internal compiler error

    I am made a program to convert american money to canadian but I wanted to play around with it and use a switch statement so that you can go from american to canadian and visa versa, anyways this is my code:

    Code:
    #include <stdio.h>
    
    int choice;
    float userNum=0;
    double userNumA=0;
    #define US  1.57551;
    #define CAN 1;
    
    int main(void)
    {
    	
    	while(1)
    	{
    	printf("This converter will either convert Canadian money to US, or visa versa.\n");
    	printf("When you want to quit simply enter any number that has a value less than 1.\n");
    	printf("1. American to Canadian \n2. Canadian to American.");
    	scanf("%d", &choice);
    
    	switch(int)
    	{
    	case '1':
    		printf("Please enter the American amount now: ");
    		scanf("%f",userNum); 
    
    		if(userNum>=1)
    		{
    			userNumA =userNum * US;
    			printf("\nAmerican amount:%f -- Canadian amount: %f\n\n",userNum, userNumA);
    	
    	}
    	else
    	{
    		break;
    	}
    
    	case '2':
    		printf("Please enter the Canadian amount now: ");
    		scanf("%f",userNum);
    
    	if(userNum>=1)
    	{
    		userNumA = userNum / US;
    		printf("\nCanadian amount:%f -- American amount: %f\n\n",userNum, userNumA);
    	
    	}
    	else
    	{
    		break;
    	}
    
    	default:
    		printf("Please enter either 1 or 2.");
    	}
    
    	printf("\nThank you for using my converter\n\n");
    	return 0;
    }
    }
    Here is the error:

    fatal error C1001: INTERNAL COMPILER ERROR

    It started when I changed the divide symbol from \ to / because otherwise I get an error about an empty carrige or something, can someone help or at least explain what an internal error is and what causes it?? thanks a lot.

  2. #2
    Registered User moi's Avatar
    Join Date
    Jul 2002
    Posts
    946
    switch (choice) not switch (int)
    case 1: not case '1':
    case 2: not case '2':
    scanf("%f", &userNum); not scanf("%f", userNum);
    also i don't think you understand the flow control of the switch keyword. look at this and see if it helps
    hello, internet!

  3. #3
    Registered User CAP's Avatar
    Join Date
    May 2002
    Posts
    179
    I know there are lots of problems .

    On your post Moi I tried to download the file but it just took me to a blank website, but my internet is screwed up and I can see that other people have downloaded it, so I haven't seen it yet.

    I worked on the switch statment and I put in "switch(choice)" so that works but I still have one major problem, when the program is run and you chose option 1, it will do the calculations but then it goes on and does option 2 and the defalut option as well, but if you only chose option 2 then it goes on and does option 2 and then the default one as well. Can someone give me a hint at least or some help on how to stop the program when it is done its intended calculation. I have posted my code below and you will see that in default I put in a goto statement, I am told that these are bad couldn't remember any other way to get the program to restart(just thought I would explain what I was thinking). I want the program to restart to allow the user to reuse the program again and again. One more thing I want to mention(I know I am talking a lot)but when I enter 0, or a value lower than 1 the program doesn't exit.

    Here is my code:

    Code:
    #include <stdio.h>
    
    int choice;
    float userNum=0;
    double userNumA=0;
    #define US  1.57551
    
    int main(void)
    {
    	
    body:
    
    	while(1)
    	{
    	printf("This converter will either convert Canadian money to US, or visa versa.\n");
    	printf("When you want to quit simply enter any number that has a value less than 1.\n");
    	printf("1. American to Canadian \n2. Canadian to American.\n");
    	scanf("%d", &choice);
    
    	switch(choice)
    	{
    	case 1:
    		printf("Please enter the American amount now: ");
    		scanf("%f", &userNum); 
    
    		if(userNum>=1)
    		{
    			userNumA =userNum * US;
    			printf("\nAmerican amount:%f -- Canadian amount: %f\n\n",userNum, userNumA);
    	
    	}
    	else
    	{
    		break;
    	}
    
    	case 2:
    		printf("Please enter the Canadian amount now: ");
    		scanf("%f",&userNum);
    
    	if(userNum>=1)
    	{
    		userNumA = userNum / US;
    		printf("\nCanadian amount:%f -- American amount: %f\n\n",userNum, userNumA);
    	
    	}
    	else
    	{
    		break;
    	}
    
    	default:
    		goto body;
    		printf("Please enter either 1 or 2.");
    
    	}
    
    	printf("\nThank you for using my converter\n\n");
    	return 0;
    }
    }
    Thanks a lot but no one has to answer all of those questions, if you can just give me a hint would be helpful.
    Last edited by CAP; 08-15-2002 at 06:35 PM.
    -Microsofts Visual C++ Introductory Kit-
    Current Projects: Learning Everything C.

    Everyone has a photographic memory, some people just don't have any film.
    ______________________________

    When was the last time you went for a colon cleansing? Because quite frankly, you're so backed up with crap that it's spilling out your mouth

  4. #4
    Registered User moi's Avatar
    Join Date
    Jul 2002
    Posts
    946
    here is the file i attached posted here:


    Code:
    #include <stdio.h>
    
    int choice;
    float userNum=0;
    double userNumA=0;
    #define US 1.57551
    #define CAN 1
    
    int main(void)
    {
      printf("This converter will either convert Canadian money to US, or visa versa.\n");
      printf("When you want to quit simply enter any number that has a value less than 1.\n");
      printf("1. American to Canadian \n2. Canadian to American.");
      scanf("%d", &choice);
    
      while (1)
      {
        switch(choice)
        {
          case 1:
          {
            printf("Please enter the American amount now: ");
            scanf("%f", &userNum); 
            if(userNum >= 1)
            {
              userNumA = userNum * US;
              printf("\nAmerican amount:%f -- Canadian amount: %f\n\n",userNum, userNumA);
            }
            else
            {
              printf("\nThank you for using my converter\n\n");
              return 0;
            }
            break;
          }
          case 2:
          {
            printf("Please enter the Canadian amount now: ");
            scanf("%f", &userNum);
    
            if(userNum >= 1)
            {
              userNumA = userNum / US;
              printf("\nCanadian amount:%f -- American amount: %f\n\n",userNum, userNumA);
    	
            }
            else
            {
              printf("\nThank you for using my converter\n\n");
              return 0;
            }
            break;
          }
          default:
            printf("Please enter either 1 or 2.");
        }
      }
      return 0;
    }
    hello, internet!

  5. #5
    Green Member Cshot's Avatar
    Join Date
    Jun 2002
    Posts
    892
    This one allows you to change the mode:

    Code:
    #include <stdio.h>
    
    int choice;
    float userNum=0;
    double userNumA=0;
    #define US 1.57551
    #define CAN 1
    
    int main(void)
    {
       printf("This converter will either convert Canadian money to US, or visa versa.\n");
       printf("When you want to quit simply enter any number other than 1 or 2.\n");
       while (1)
       {
          printf("1. American to Canadian \n2. Canadian to American\nAny Other Number to Quit\n:");
          scanf("%d", &choice);
    
          if(choice == 1)
          {
             printf("Please enter the American amount now: ");
             scanf("%f", &userNum);
             if(userNum >= 0)
             {
                userNumA = userNum * US;
                printf("\nAmerican amount:%f -- Canadian amount: %f\n\n",userNum, userNumA);
             }
             else
                printf("\nInvalid Value.\n");
          }
          else if(choice == 2)
          {
             printf("Please enter the Canadian amount now: ");
             scanf("%f", &userNum);
    
             if(userNum >= 0)
             {
                userNumA = userNum / US;
                printf("\nCanadian amount:%f -- American amount: %f\n\n",userNum, userNumA);
             }
             else
                printf("\nInvalid Value.\n");
          }
          else
             break;
    
       }
       printf("\nThank you for using my converter\n\n");
       return 0;
    }
    Now you can try writing code that parses for invalid user input such as characters.
    Try not.
    Do or do not.
    There is no try.

    - Master Yoda

  6. #6
    Registered User CAP's Avatar
    Join Date
    May 2002
    Posts
    179
    OK cool, thanks a lot, I will try and fix my code and then try it with if and else statements.
    -Microsofts Visual C++ Introductory Kit-
    Current Projects: Learning Everything C.

    Everyone has a photographic memory, some people just don't have any film.
    ______________________________

    When was the last time you went for a colon cleansing? Because quite frankly, you're so backed up with crap that it's spilling out your mouth

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Errors including <windows.h>
    By jw232 in forum Windows Programming
    Replies: 4
    Last Post: 07-29-2008, 01:29 PM
  2. DX - CreateDevice - D3DERR_INVALIDCALL
    By Tonto in forum Game Programming
    Replies: 3
    Last Post: 12-01-2006, 07:17 PM
  3. using c++ in c code
    By hannibar in forum C Programming
    Replies: 17
    Last Post: 10-28-2005, 09:09 PM
  4. Problem with Visual C++ Object-Oriented Programming Book.
    By GameGenie in forum C++ Programming
    Replies: 9
    Last Post: 08-29-2005, 11:21 PM
  5. ras.h errors
    By Trent_Easton in forum Windows Programming
    Replies: 8
    Last Post: 07-15-2005, 10:52 PM