Problems with Break in C

This is a discussion on Problems with Break in C within the C Programming forums, part of the General Programming Boards category; Hi guys, I'm learning C and I'm on the break tutorial but when I run this program nothing happens any ...

  1. #1
    Registered User
    Join Date
    Nov 2007
    Posts
    26

    Problems with Break in C

    Hi guys,
    I'm learning C and I'm on the break tutorial but when I run this program nothing happens any advice?

    Code:
     
    #include <stdio.h>
    
    int main()
    {
    int option, conversion, pound, dollar;
    printf("Enter 1 for >$\n");
    printf("Enter 2 for $>\n");
    scanf("%d", &option);
    
    switch( option ) 
    {
    case 1:
    printf("Enter the amount in pounds");
    scanf("%d",&pound);
    conversion = pound * 2;
    printf("%d",pound);
    break;
    
    case 2:
    printf("Enter the amount in dollars");
    scanf("%d", &dollar);
    conversion = dollar / 2;
    printf("%d",dollar);
    break;
    
    
    }
    getchar();
    getchar();
    
    }
    Thanks

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    What do you mean by nothing happens? Do you mean that conversion doesn't print? Why would you expect that conversion should print?

  3. #3
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Posts
    22,897
    Are you asking why it's displaying exactly what you entered?
    Because you clearly save the converted amount into the variable "conversion", but print the input instead.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  4. #4
    Registered User
    Join Date
    Nov 2007
    Posts
    26
    I've changed what it prints but its still the same. I compile it as break.exe and when I run it in a command prompt it simply does nothing and brings back the command prompt input line i.e. C:\Users etc

    Code:
    #include <stdio.h>
    
    int main()
    {
    int option, conversion, pound, dollar;
    printf("Enter 1 for >$\n");
    printf("Enter 2 for $>\n");
    scanf("%d", &option);
    
    switch( option ) 
    {
    case 1:
    printf("Enter the amount in pounds");
    scanf("%d",&pound);
    conversion = pound * 2;
    printf("%d",conversion);
    break;
    
    case 2:
    printf("Enter the amount in dollars");
    scanf("%d", &dollar);
    conversion = dollar / 2;
    printf("%d",conversion);
    break;
    
    
    }
    getchar();
    getchar();
    
    }

  5. #5
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,752
    Maybe name your program something else.
    Code:
    C:\>break /?
    Sets or Clears Extended CTRL+C checking on DOS system
    
    This is present for Compatibility with DOS systems. It has no effect
    under Windows.
    
    If Command Extensions are enabled, and running on the Windows
    platform, then the BREAK command will enter a hard coded breakpoint
    if being debugged by a debugger.
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  6. #6
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,006
    Quote Originally Posted by AKalair View Post
    I've changed what it prints but its still the same. I compile it as break.exe and when I run it in a command prompt it simply does nothing and brings back the command prompt input line i.e. C:\Users etc
    Maybe try giving it a different name.
    http://technet.microsoft.com/en-us/l...chNet.10).aspx
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  7. #7
    Registered User
    Join Date
    Nov 2007
    Posts
    26
    Thank You

    That fixed it i'll bookmark that site

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help it won't compile!!!!!
    By esbo in forum C Programming
    Replies: 58
    Last Post: 01-04-2009, 03:22 PM
  2. ascii rpg help
    By aaron11193 in forum C Programming
    Replies: 18
    Last Post: 10-29-2006, 01:45 AM
  3. Base converter libary
    By cdonlan in forum C++ Programming
    Replies: 22
    Last Post: 05-15-2005, 02:11 AM
  4. Problems with switch()
    By duvernais28 in forum C Programming
    Replies: 13
    Last Post: 01-28-2005, 10:42 AM
  5. Converting Numbers to Words
    By denizengt in forum C Programming
    Replies: 20
    Last Post: 11-05-2003, 09:19 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21