Modular Programming Help

This is a discussion on Modular Programming Help within the C Programming forums, part of the General Programming Boards category; shiryu3, you need to stop giving out solutions. Logic is the very key to programming and it is something that ...

  1. #16
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,554
    shiryu3, you need to stop giving out solutions. Logic is the very key to programming and it is something that any student must learn. If you give out solutions, you hamper their ability to think logically and make the logic bit work!
    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.

  2. #17
    Registered User
    Join Date
    Mar 2009
    Posts
    30
    I admit I'm typing out solutions, but nothing that's going to give away the overall program. The requester here had a lot of broken C syntax so I felt it necessary that he be provided with something with proper syntax.

  3. #18
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,554
    Fixing syntax is fine, but unfortunately, fixing logic is not. That is where you must be careful.
    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. #19
    Registered User
    Join Date
    Aug 2009
    Posts
    43
    hey shir, thanks for all the help you've given me. My program was working perfect just a second ago and then I went to run it again and my main menu keeps being displayed twice in a row for some reason now!

    Code:
    #include <stdio.h>
    int main()
    {
    
            int MenuOptions() ;
            char choice ;
            int number, i ;
    
    
            while ( ( choice = MenuOptions() ) != 'q' )
            {
                    switch(choice)
                    {
                            case 'a':
                                    printf("Name\n") ;
                                    break ;
    
                            case 'b':
                                    printf("Date\n") ;
                                    break ;
    
                            case 'c':
                                    printf("Enter a number: ") ;
                                    scanf("%d", &number) ;
    
                                    if ( number >= 0 && number <= 50 )
                                    {
                                    for ( i = 0 ; i <= number ; i++ )
                                    printf("%d ", i );
                                    printf("\n") ;
                                    }
                                    else
                                    printf("Invalid number!\n") ;
                                    break ;
    
                            default:
                                    break ;
                    }
            }
            return 0 ;
    }
    
    int MenuOptions()
    {
            char letter ;
    
            printf("Press a for Student Name\n") ;
            printf("Press b Tutorial Date & Time\n") ;
            printf("Press c Positive Numbers\n") ;
            printf("Press q to Quit\n") ;
    
            scanf("%c", &letter) ;
    
            return letter ;
    }
    So for example, I press a for student name, the name appears but when it goes to the menu it comes up

    Press a for Student Name
    Press b Tutorial Date & Time
    Press c Positive Numbers
    Press q to Quit
    Press a for Student Name
    Press b Tutorial Date & Time
    Press c Positive Numbers
    Press q to Quit

    the loop still works, i just can't see why it would display the menu twice?

  5. #20
    DESTINY BEN10's Avatar
    Join Date
    Jul 2008
    Location
    in front of my computer
    Posts
    804
    Give a space in scanf like this-
    Code:
    scanf(" %c",&letter);
    When for the first time you enter 'a' and hit "ENTER" key this gets stored in the input buffer and the next call to scanf takes this as the next letter, maknig the default case to become true. That's why it breaks and asks the menu shows up twice.
    HOPE YOU UNDERSTAND.......

    By associating with wise people you will become wise yourself
    It's fine to celebrate success but it is more important to heed the lessons of failure
    We've got to put a lot of money into changing behavior


    PC specifications- 512MB RAM, Windows XP sp3, 2.79 GHz pentium D.
    IDE- Microsoft Visual Studio 2008 Express Edition

  6. #21
    Registered User
    Join Date
    Aug 2009
    Posts
    43
    ahhh it worked!

    thanks! I must have edited it without thinking, I would have never known that was the reason why the menu displays twice

    thanks!

  7. #22
    Registered User
    Join Date
    Mar 2009
    Posts
    30
    No problem DJ, please take the time to compare this working code with your original post and look over all the broken syntax issues.

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. modular c programming
    By akrlot in forum C Programming
    Replies: 5
    Last Post: 10-25-2007, 07:00 AM
  2. Modular
    By loopshot in forum Game Programming
    Replies: 7
    Last Post: 01-20-2006, 06:24 PM
  3. Modular math
    By PJYelton in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 10-01-2003, 08:35 AM
  4. Modular Division problem
    By Malek in forum C++ Programming
    Replies: 7
    Last Post: 05-24-2003, 06:08 PM
  5. Completely modular motherboards?
    By SMurf in forum A Brief History of Cprogramming.com
    Replies: 10
    Last Post: 02-23-2003, 11:56 AM

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