Code won't compile! O.o

This is a discussion on Code won't compile! O.o within the C Programming forums, part of the General Programming Boards category; Just need someone to tell me where I'm going wrong... Would someone kindly look over my small program? It's 150 ...

  1. #1
    Registered User
    Join Date
    Jan 2006
    Posts
    10

    Unhappy Code won't compile! O.o

    Just need someone to tell me where I'm going wrong...

    Would someone kindly look over my small program? It's 150 lines long BUT has much commenting, so will be easy to understand. Actual program coding is ~100 lines. Very short and simple. I have tried many things but no luck, so I thought an experianced coder could pick up the syntax errors or whatever.

    I have finished writing what I want it to do...

    User inputs Roman numeral, it converts it to Arabic. *done*
    User inputs Arabic numeral, it converts it to Roman. *done*
    User inputs text file, converts it to Roman, outputs to new text file. *done*
    User inputs text file, no calculation to convert to Arabic yet.

    But I'm not asking for help with that, I would like someone to have a quick scan through to see why its not compiling, check syntax etc... so it runs and works.

    I don't wish to post the code on here as it is coursework, so please reply with contact info or add me to MSN or email me: <snipped>

    Rich
    Last edited by Salem; 01-06-2006 at 01:03 AM. Reason: Removed email address

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    How about instead paying attention to what your compiler is saying? You know, the actual reason why it's not compiling. There really is a reason to read those lines after all.


    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    cwr
    cwr is offline
    Registered Luser cwr's Avatar
    Join Date
    Jul 2005
    Location
    Sydney, Australia
    Posts
    869
    The least you could have done is posted the errors you were getting, and the lines of code that they referred to.

    I highly doubt that (and hope not) anybody is going to contact you to personally go through your code. The point of a forum is so everyone can benefit from the replies and posts, it's not your personal support service.

  4. #4
    Registered User
    Join Date
    Jan 2006
    Posts
    10
    I have read the errors im getting and have tried many things to sort it.

    Code:
    Compiling...
    miniproject.cpp
    miniproject.cpp(1) : warning C4067: unexpected tokens following preprocessor directive - expected a newline
    miniproject.cpp(24) : error C2143: syntax error : missing ';' before '{'
    miniproject.cpp(24) : error C3861: 'arabicToRoman': identifier not found, even with argument-dependent lookup
    miniproject.cpp(25) : error C2065: 'output' : undeclared identifier
    miniproject.cpp(26) : error C2065: 'input' : undeclared identifier
    miniproject.cpp(26) : fatal error C1903: unable to recover from previous error(s); stopping compilation
    Code:
    	arabicToRoman() {
    		output = "";
    		while (input >= 1000) {
    			output = output + "M";
    			input - 1000;
    		}
    first line here is line 24 in the program. arabicToRoman() is a procedure.. i dont know what it means by identifier not found. and "output" "input" are indentified. *sigh*

  5. #5
    Registered User
    Join Date
    Jan 2006
    Posts
    10
    Quote Originally Posted by cwr
    The least you could have done is posted the errors you were getting, and the lines of code that they referred to.

    I highly doubt that (and hope not) anybody is going to contact you to personally go through your code. The point of a forum is so everyone can benefit from the replies and posts, it's not your personal support service.
    Why do you hope that someone wont go through my code. Not asking them to fix it all, just tell me where i'm going wrong so I can fix it. How am i supposed to learn if i dont know the right way.

  6. #6
    cwr
    cwr is offline
    Registered Luser cwr's Avatar
    Join Date
    Jul 2005
    Location
    Sydney, Australia
    Posts
    869
    Well, this is a C forum, but you appear to be posting (edit: or trying to compile C as ) C++. I'm not a C++ person, but I recall that C++ won't let you have bare functions without an explicit return value. In C, your function declaration above is valid but dodgy. You should use int arabicToRoman(void) { or void arabitToRoman(void) { depending on whether it returns something. (int could be another type)

    Another issue is that you should have a prototype of the function above.

    As for output and input, where are they declared? Unless they're global (outside any function), it won't be in scope for your arabicToRoman function.

    I don't hope someone won't go through your code, my point was that you shouldn't expect people to personally contact you outside the forum to get help.

    Edit:

    Another thing, if this is C, and not C++, then the code you posted makes little sense. Assuming output is a char pointer or char array, such things won't work. You can't concatenate strings like that with a + operator. You may be able to do such magic in C++, though.
    Last edited by cwr; 01-05-2006 at 09:15 PM.

  7. #7
    Registered User
    Join Date
    Jan 2006
    Posts
    10
    It's meant to be C. but using ms visual c++

    the procedure deals with numbers and characters, so what do i use? float arabicToRoman(void) ?

    it sends the value to the "output" variable.

  8. #8
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    It's very simple:

    If your function is to take no arguments, declare it's argument list as void. Otherwise, stick whatever arguments you're going to pass to it as types, in the order you wish them to be passed. For example, if I have a function that is to take an integer and a float, I might do something like this:
    Code:
    void myfunction( int a, float b )
    {
        ...stuff here...
    }
    Likewise, if the function is not going to return anything, we make it have a void return type. Otherwise, we pick the one type we wish to return. Possibly like so:
    Code:
    int myfunction( int a, float b )
    {
        ...stuff goes here...
        return (something here that's an int);
    }
    Now then, if you're going to have something called output and input, you need those variables to actually be declared some place. You aren't declaring any variables inside your function, which means it can't see anything called output and input, unless you have them declared as global variables some place in scope.


    Quzah.
    Hope is the first step on the road to disappointment.

  9. #9
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,265
    Post all your code. It also appears you have a severe lack of understanding regarding the mechanics of C strings. You need to pick up a book, or read some tutorials.

  10. #10
    cwr
    cwr is offline
    Registered Luser cwr's Avatar
    Join Date
    Jul 2005
    Location
    Sydney, Australia
    Posts
    869
    Quote Originally Posted by Coldcore
    It's meant to be C. but using ms visual c++
    In addition to what's been said above, I suggest you convince your compiler to compile it as C code instead of C++, if possible.

    There are things that are legal in C but not in C++, and obviously vice versa, and there are things that are legal in both, but have different results.

  11. #11
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,006
    Some background.
    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.*

  12. #12
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,006
    This may also be of interest. [A search for "roman numerals" by "Prelude": results as posts -- I just happened to know that.]
    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.*

  13. #13
    Registered User
    Join Date
    Jan 2006
    Posts
    10
    Ahh looks interesting, i'll give that a read now, thanks!

  14. #14
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Wow your code is really really bad.

    1 - You use all global variables.
    2 - The function main should be returning an int. There's a FAQ on it.
    3 - You are trying to have nested functions, which is not allowed.
    4 - You are confusing the assignment operator with the equality operator. = assigns a value. == tests for equality.
    5 - You keep trying to assign strings to floating point numbers.


    Quzah.
    Hope is the first step on the road to disappointment.

  15. #15
    Registered User
    Join Date
    Jan 2006
    Posts
    10
    >_< I know it's bad. I kind of built it up to make it look like what i want it to do then i make it work... ill try sort the things you've mentioned. Thanks.

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

Similar Threads

  1. Code won't compile
    By monkles in forum C Programming
    Replies: 3
    Last Post: 05-28-2009, 02:45 PM
  2. Compile Errors in my Code. Can anyone help?
    By DGLaurynP in forum C Programming
    Replies: 1
    Last Post: 10-06-2008, 10:36 AM
  3. This code won't compile in Red Hat Linux 9
    By array in forum Linux Programming
    Replies: 7
    Last Post: 04-27-2004, 07:30 AM
  4. << !! Posting Code? Read this First !! >>
    By kermi3 in forum Linux Programming
    Replies: 0
    Last Post: 10-14-2002, 02:30 PM
  5. How do they compile code for an OS ?
    By Nutshell in forum A Brief History of Cprogramming.com
    Replies: 49
    Last Post: 03-28-2002, 12:16 AM

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