Thread: Error count exceeds 100

  1. #1
    Registered User
    Join Date
    Sep 2011
    Posts
    4

    Error count exceeds 100

    Hey all,

    I started creating my first C program to test my comprehension of the basics, but I'm running into over 100 syntax errors. I can't tell what I'm doing wrong. Here's the code:

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <iostream>
    #include <cmath.h>
    
    void mainmenu();
    int joke();
    int calculator();
    int addition();
    int subtraction();
    int multiplication();
    int division();
    int add ( int x, int y );
    int subtract ( int x, int y );
    int multiply ( int x, int y );
    int divide ( int x, int y );
    
    int main()
    {
        system ("cls");
        printf("Hello. Welcome to the program.\n");
        printf("Press any key to continue...\n");
        getchar();
        mainmenu();
    
    }
    
    void mainmenu()
    {
    
        int menu1choice;
    
        printf("Menu 1\n");
            printf("~~~~~~~~~~\n");
            printf("1. Tell me a joke.\n");
            printf("2. Perform a simple calculation.\n");
            printf("3. Move to Menu 2.\n");
            scanf("%d", &menu1choice);
            switch ( menu1choice ) {
            case 1:{
                joke();
                break;
                   }
            case 2:{
                calculator();
                break;
                   }
            }
        }
    }
    
    int joke()
    {
        system("cls");
        printf("How do you get holy water? \n");
        system("pause");
        printf("You boil the hell out of it. \n");
        system("pause");
        system("cls");
        mainmenu();
        
    }
    
    int calculator()
    {
        int calculatorchoice;
    
        system("cls");
        printf("What type of calculation would you like to make? \n");
        printf("1.  Addition \n");
        printf("2.  Subtraction \n");
        printf("3.  Multiplication \n");
        printf("4.  Division \n");
        scanf("%d", &calculatorchoice);
        switch ( calculatorchoice ){
            case 1:{
                addition();
                break;
                   }
            case 2:{
                subtraction();
                break;
                   }
            case 3:{
                multiplication();
                break;
                   }
            case 4:{
                division();
                break;
                   }
        }
    }
    
    int addition()
    {
        int x;
        int y;
    
        system("cls");
        printf("Please input two numbers to be added: ");
        scanf( "%d", &x );
        scanf( "%d", &y );
        printf( "The product of your two numbers is %d\n", add( x, y ) );
        getchar();
    
    }
    Any help is appreciated

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Remove this line as there is usually no sense in including a C++ header in a C program:
    Code:
    #include <iostream>
    Change this line:
    Code:
    #include <cmath.h>
    to:
    Code:
    #include <math.h>
    You may still have more syntax errors, but don't worry about the count: fix them one by one.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Sep 2011
    Posts
    4
    Thanks!

  4. #4
    Registered User
    Join Date
    Dec 2011
    Posts
    795
    In addition to that, you've got an extra "}" on mainmenu, all the calculating functions but addition aren't defined (and produce linker errors), and you're not returning anything from functions that are supposed to return ints.

  5. #5
    Registered User andrew89's Avatar
    Join Date
    Dec 2011
    Location
    Indiana, United States
    Posts
    80
    You just couldn't settle for a Hello World eh?

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <math.h>
     
    void mainmenu();
    int joke();
    int calculator();
    int addition();
    int add ( int x, int y );
    /*  Noted out temporarily because these functions are not yet created.
    
    int subtraction();
    int multiplication();
    int division();
    int subtract ( int x, int y );
    int multiply ( int x, int y );
    int divide ( int x, int y );
    */ 
    int main()
    {
        system ("cls");
        printf("Hello. Welcome to the program.\n");
        printf("Press any key to continue...\n");
        getchar();
        mainmenu();
     
    }
     
    void mainmenu()
    {
        int menu1choice;
        system("cls");
        printf("Menu 1\n");
            printf("~~~~~~~~~~\n");
            printf("1. Tell me a joke.\n");
            printf("2. Perform a simple calculation.\n");
            printf("3. Move to Menu 2.\n");
            scanf("%d", &menu1choice);
            switch ( menu1choice ) {
            case 1:{
                joke();
                break;
                   }
            case 2:{
                calculator();
                break;
                   }
            }
        }
     
    int joke()
    {
        system("cls");
        printf("How do you get holy water? \n");
        system("pause");
        printf("You boil the hell out of it. \n");
        system("pause");
        system("cls");
        mainmenu();
    }
     
    int calculator()
    {
        int calculatorchoice;
     
        system("cls");
        printf("What type of calculation would you like to make? \n");
        printf("1.  Addition \n");
        printf("2.  Subtraction \n");
        printf("3.  Multiplication \n");
        printf("4.  Division \n");
        scanf("%d", &calculatorchoice);
        switch ( calculatorchoice ){
            case 1:{
                addition();
                break;
                   }
    /*  Noted off because cases call functions that do not exist yet.
            case 2:{
                subtraction();
                break;
                   }
            case 3:{
                multiplication();
                break;
                   }
            case 4:{
                division();
                break;
                   }*/
        }
    }
     
    int addition()
    {
        int x;
        int y;
     
        system("cls");
        printf("Please input two numbers to be added: ");
        scanf( "%d", &x );
        scanf( "%d", &y );
        printf( "The product of your two numbers is %d\n", add( x, y ) );
        getchar();
    
    }
    int add(num1,num2)
    {}
    This compiles, but a good practice is to add a function, compile, debug, repeat. That way you don't run into 20 compiler errors. By the way, you had an extra
    Code:
    }  //made me put code tags around this -_-
    in your main menu. This is most often caused by poor indentation practices.

    EDIT: Memcpy, you beat me to that.

    * Proper indentation is encouraged for all programming languages.
    * It shows levels of nesting, nested if statements , for loops, etc.
    * Anyone reading your code can tell whats executing inside of what.
    * It shows scope. If everything is indented you know the scope of variables.
    * Easier to read.
    * Better programming sense.

    Suggested reading:
    A development process
    If, for some reason, I don't make any sense at all, it's highly likely that I've been up all night on some strange bender that isn't normal. I likely unarmed and far from dangerous. While I haven't been known to physically harm anyone or anything else, there have been unsubstantiated reports that I have driven others into both a hazy stupor as well as a blinding rage. Otherwise, I hope I helped.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. odd even count error
    By neveragn in forum C Programming
    Replies: 12
    Last Post: 10-25-2011, 03:02 PM
  2. Replies: 10
    Last Post: 11-18-2008, 11:52 PM
  3. Linker error _text exceeds 64K
    By Chalakorn in forum C Programming
    Replies: 13
    Last Post: 01-07-2006, 12:16 PM
  4. Again Character Count, Word Count and String Search
    By client in forum C Programming
    Replies: 2
    Last Post: 05-09-2002, 11:40 AM
  5. Replies: 2
    Last Post: 05-05-2002, 01:38 PM