This should be so simple!!!

This is a discussion on This should be so simple!!! within the C Programming forums, part of the General Programming Boards category; I've created this program and I'm trying to run in codeblocks 8.02 but it doesn't get further than the intial ...

  1. #1
    Registered User JM1082's Avatar
    Join Date
    Mar 2011
    Posts
    51

    Angry This should be so simple!!!

    I've created this program and I'm trying to run in codeblocks 8.02 but it doesn't get further than the intial user input.

    The program should use a menu system to run funtions which double, square or cube their input number.

    Any ideas???

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    
    int doublenum(int userin);
    int square(int userin);
    int cube(int userin);
    
    int main(void)
    {
        int menuchoice = 0, userin, out;
    
        printf("\nEnter a number: ");
        scanf("%d", &userin);
    
        while(menuchoice != 4);
            {
                printf("\n1\tDouble\n2\tSquare\n3\tCube4\tQuit\n\nPlease choose an option: ");
                scanf("%d", &menuchoice);
    
                switch (menuchoice) {
                    case 1: out = doublenum(userin);
                            printf("\n%d", out);
                        break;
                    case 2: out = square(userin);
                            printf("\n%d", out);
                        break;
                    case 3: out = cube(userin);
                            printf("\n%d", out);
                        break;
                    default: printf("\nMENU CHOICE ERROR!\n");
                        break;
                }
            }
        return 0;
    }
    
    int doublenum(int userin)
    {
        return userin + userin;
    }
    
    int square(int userin)
    {
        return userin * userin;
    }
    
    int cube(int userin)
    {
        return userin * userin * userin;
    }

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,590
    > while(menuchoice != 4);
    Watch the ; at the end.
    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.

  3. #3
    Registered User
    Join Date
    Oct 2006
    Posts
    250
    There's your error:

    Code:
    while(menuchoice != 4);
    iMalc: Your compiler doesn't accept misspellings and bad syntax, so why should we?
    justin777: I have no idea what you are talking about sorry, I use a laptop and there is no ascii eject or something

  4. #4
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,802
    You probably should add a case 4 section of code. You really don't want an error message to be printed when you press 4 to quit the application when it is a valid value according to your menu.
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Simple Socket Library Not so simple
    By jbully in forum C Programming
    Replies: 4
    Last Post: 12-23-2010, 08:23 AM
  2. Simple program...simple problem?
    By deadherorising in forum C Programming
    Replies: 2
    Last Post: 03-12-2009, 08:37 PM
  3. Simple program, not so simple problem
    By nolsen in forum C++ Programming
    Replies: 2
    Last Post: 01-18-2008, 09:28 AM
  4. simple simple design question
    By Chaplin27 in forum C++ Programming
    Replies: 6
    Last Post: 05-31-2005, 11:33 PM
  5. Replies: 1
    Last Post: 07-20-2002, 06:33 PM

Tags for this Thread


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