haveing a problem with my Code

This is a discussion on haveing a problem with my Code within the C++ Programming forums, part of the General Programming Boards category; So I have this code and when I try to compile it I get Declaration terminated incorrectly.. its states that ...

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

    haveing a problem with my Code

    So I have this code and when I try to compile it I get Declaration terminated incorrectly.. its states that this is located on line 16. I'm using Borland C++ 5.5.1 for Win32 to compile.

    here is my code

    Code:
     #include <iostream>
    #include <stdio.h>
    #include <iostream.h>
    
    using namespace std;
    
    int main()
    {
    cout<<"hello World!! Please press enter to continue! ";
    getchar();
    cout<<"This is one of Will's simple C++ programs...He is a noob programer =D";
    return 0;
    }
    
    
    {
    cout << "would you like to see me do some mathimatical calculations? Then press enter!"; 
    getchar();
    return 0;
    }  
    
    {
    float num1;
      float num2;
      int num3;
      float num4;
    cout << "please Enter a number! any number!!!"; <<endl;
    cin >> num1;
    
    cout << "please Enter Another number!"; <<endl;
    cin >> num2
    
    cout << "Now Choose an operation!!1 to add, 2 to subtract, 3 to multiply, 4 to divide." <<endl;
    cin >> num3;
    
    if (num3 >4 || num3 <1)
      {
        cout << "Your operation choice isn't valid!  Please run the program again." << endl;
        cout << "Press Enter to end program." << endl;
        getchar();
        return 0;
      }
      else
      {
            if (num3 == 1)
            {
                num4 = num1 + num2;
                cout << "Result is: "<<  num4 << endl;
            }
            else if (num3 == 2)
            {
                num4 = num1 - num2;
                cout << "Result is: "<<  num4 << endl;
            }
            else if (num3 == 3)
            {
                num4 = num1 * num2;
                cout << "Result is: "<<  num4 << endl;
            }
            else if (num3 == 4)
            {
                num4 = num1 / num2;
                cout << "Result is: " <<  num4 << endl;
            }
    
      }
    
      cout << "Press Enter to end program." << endl;
      getchar();
    
      return 0;
    }

  2. #2
    Jack of many languages Dino's Avatar
    Join Date
    Nov 2007
    Location
    Katy, Texas
    Posts
    2,309
    This is your complete program:
    Code:
     #include <iostream>
    #include <stdio.h>
    #include <iostream.h>
    
    using namespace std;
    
    int main()
    {
    cout<<"hello World!! Please press enter to continue! ";
    getchar();
    cout<<"This is one of Will's simple C++ programs...He is a noob programer =D";
    return 0;
    }
    Were you wanting to do something else with the rest of the code?
    Mac and Windows cross platform programmer. Ruby lover.

    Quote of the Day
    12/20: Mario F.:I never was, am not, and never will be, one to shut up in the face of something I think is fundamentally wrong.

    Amen brother!

  3. #3
    Registered User
    Join Date
    Sep 2009
    Posts
    4
    Yes the rest of that code represents a calculator type application which i derived from is this here. This IS a working program i compiled and tested it myself 100% working... so if you could kindly show me how to get both of these working together somehow that would be great then i can move on with my tutorial D

    Code:
    #include <stdio.h>
    #include <iostream.h>
    
    int main()
    {
    
      float num1;
      float num2;
      int num3;
      float num4;
    
      cout << "Enter a number: " << endl;
      cin >> num1;
    
      cout << "Enter a second number: " << endl;
      cin >> num2;
    
      cout << "Choose an operation." << endl;
      cout << "Enter 1 to add, 2 to subtract, 3 to multiply, 4 to divide: " << endl;
      cin >> num3;
    
    
      if (num3 >4 || num3 <1)
      {
        cout << "Your operation choice isn't valid!  Please run the program again." << endl;
        cout << "Press Enter to end program." << endl;
        getchar();
        return 0;
      }
      else
      {
            if (num3 == 1)
            {
                num4 = num1 + num2;
                cout << "Result is: "<<  num4 << endl;
            }
            else if (num3 == 2)
            {
                num4 = num1 - num2;
                cout << "Result is: "<<  num4 << endl;
            }
            else if (num3 == 3)
            {
                num4 = num1 * num2;
                cout << "Result is: "<<  num4 << endl;
            }
            else if (num3 == 4)
            {
                num4 = num1 / num2;
                cout << "Result is: " <<  num4 << endl;
            }
    
      }
    
      cout << "Press Enter to end program." << endl;
      getchar();
    
      return 0;
    }
    but obviously i am fail XD
    Last edited by Illsaudie; 09-12-2009 at 12:25 PM.

  4. #4
    Jack of many languages Dino's Avatar
    Join Date
    Nov 2007
    Location
    Katy, Texas
    Posts
    2,309
    So, the easiest thing to do would be to take your found code and replace the function name of "main" with your own, the paste the whole thing in your program, and then call your newly named function from your main. Then, you will have perfectly working code that you completely don't understand.
    Mac and Windows cross platform programmer. Ruby lover.

    Quote of the Day
    12/20: Mario F.:I never was, am not, and never will be, one to shut up in the face of something I think is fundamentally wrong.

    Amen brother!

  5. #5
    Registered User
    Join Date
    Sep 2009
    Posts
    4
    done and still telling me Error E2040 test.cpp (line)16: Declaration terminated incorrectly. I just began some tutorials a few hours ago from this so i apologize for lack of understanding : | the problem doesnt seem to be with the calculator program but with this smaller chunk here

    Code:
    #include <iostream>
    #include <stdio.h>
    #include <iostream.h>
    
    using namespace std;
    
    int main()
    {
    cout<<"hello World!! Please press enter to continue! ";
    getchar();
    cout<<"This is one of Will's simple C++ programs...He is a noob programer =D";
    return 0;
    }
    
    cout << "would you like to see me do some mathimatical calculations? Then press enter!"; 
    getchar();*/<-----right here is where its pointing */
    return 0;
    }
    Last edited by Illsaudie; 09-12-2009 at 12:47 PM.

  6. #6
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Quote Originally Posted by Illsaudie View Post
    done and still telling me Error E2040 test.cpp (line)16: Declaration terminated incorrectly. I just began some tutorials a few hours ago from this so i apologize for lack of understanding : | the problem doesnt seem to be with the calculator program but with this smaller chunk here

    Code:
    #include <iostream>
    #include <stdio.h>
    #include <iostream.h>
    
    using namespace std;
    
    int main()
    {
    cout<<"hello World!! Please press enter to continue! ";
    getchar();
    cout<<"This is one of Will's simple C++ programs...He is a noob programer =D";
    return 0;
    }  //OH LOOK WHERE DOES THIS CURLY BRACE GO?
    
    cout << "would you like to see me do some mathimatical calculations? Then press enter!"; 
    getchar();*/<-----right here is where its pointing */
    return 0;
    }
    We do expect you, as a programmer, to be able to count at least to one. And to know what return does, for that matter. You cannot return, and you cannot put your one close curly brace, until the end of your code.

  7. #7
    Registered User
    Join Date
    Sep 2009
    Posts
    4
    ah >.< simple mistake so sorry >.> like i said im just starting out i will return once i've finished a few courses... but thnx

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Code problem
    By sybariticak47 in forum C++ Programming
    Replies: 9
    Last Post: 02-28-2006, 11:50 AM
  2. Problem with game code.
    By ajdspud in forum C++ Programming
    Replies: 5
    Last Post: 02-14-2006, 06:39 PM
  3. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 04:00 PM
  4. problem with selection code
    By DavidP in forum Game Programming
    Replies: 1
    Last Post: 06-14-2004, 02:05 PM
  5. Replies: 5
    Last Post: 12-03-2003, 05:47 PM

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