Thread: yet another question ;)

  1. #1
    Registered User
    Join Date
    Nov 2002
    Posts
    20

    yet another question ;)

    when you make a second source file for your project, do you still have to write #include "<iostream.h>", "int main();" or anything else for it to run? what im saying is that if you write it in the first source file do you have to write it again in the second?

  2. #2
    Registered User
    Join Date
    Nov 2002
    Posts
    1,109
    depends what the source file is, if it supports a class, depends what the class entails...

    i think you can only have one main per program.

  3. #3
    TransparentMember correlcj's Avatar
    Join Date
    Jun 2002
    Posts
    378

    Re: yet another question ;)

    Originally posted by blasta
    when you make a second source file for your project, do you still have to write #include "<iostream.h>", "int main();" or anything else for it to run? what im saying is that if you write it in the first source file do you have to write it again in the second?
    1st its either this #include <iostream> or #include "iostream.h". I have never seen ..."<iostream.h>" it like this but what you must do is create a header file and link every other .cpp file to you header file like so "header.h"

    I hope this makes sense.

    Good Luck!
    cj
    "Be formless, shapeless, like water... You put water into a cup, it becomes the cup, you put water into a bottle, it becomes the bottle, you put it in a teapot, it becomes the teapot... Now water can flow, or it can crash, be water my friend."
    -Bruce Lee

  4. #4
    Registered User
    Join Date
    Nov 2002
    Posts
    20
    and one more thing, how do you fix a parse error? or a syntax error?
    i get all kinds and i dont know how to fix them!

  5. #5
    Registered User moi's Avatar
    Join Date
    Jul 2002
    Posts
    946
    Originally posted by blasta
    and one more thing, how do you fix a parse error? or a syntax error?
    i get all kinds and i dont know how to fix them!
    that means your code is malformed and has lexical (is that the right word? i dont think so) things in it that dont make sense. check for missing semicolons ; missing and/or extra braces {} and parentheses ()
    hello, internet!

  6. #6
    TransparentMember correlcj's Avatar
    Join Date
    Jun 2002
    Posts
    378

    errors??

    Originally posted by blasta
    and one more thing, how do you fix a parse error? or a syntax error?
    i get all kinds and i dont know how to fix them!
    Like what kind because syntax errors range from misspellings to missing semicolons, etc.. You can also search MSDN.com for a better definition. Its a good library that I visit alot for finding definitions. Post some of those errors so maybe we can break them down 4 ya!
    K
    cj
    "Be formless, shapeless, like water... You put water into a cup, it becomes the cup, you put water into a bottle, it becomes the bottle, you put it in a teapot, it becomes the teapot... Now water can flow, or it can crash, be water my friend."
    -Bruce Lee

  7. #7
    Registered User
    Join Date
    Nov 2002
    Posts
    20
    ok, here is my program (its pretty crappy, but im just tryin to make something):
    Code:
    #inlcude <iostream>
    
    #include <stdlib.h>
    
    int main();
    
    {
    
        int answer;  //variable
        
        cout<<"What is 2+2?";  //Ya betta know that one!
        
        cin>>answer;  //here's where the value goes into our trusty variable, answer
        
        if(answer==4)  //if the user puts in 4, it will be correct.
        
        {
    
        cout<<"You are right. 2+2=4. Very good! You are very smart! Thank you for playing 2+2. Have a nice day."; 
        
        }
    
        else
        
        {
    
        cout<<"You are wrong. Get outta here!";  //This happens if the answer is anything but 2
        
        }
    
        system("PAUSE")
    
        return 0;
        
    }
    here are the errors i got (ALL of them, dont bother helping if you don't wanna):
    Code:
    1 C:\Dev-C++\Templates\Untitled1.cpp
    undefined or invalid # directive
    
    7 C:\Dev-C++\Templates\Untitled1.cpp
    parse error before `{'
    
    11 C:\Dev-C++\Templates\Untitled1.cpp
    syntax error before `<'
    
    13 C:\Dev-C++\Templates\Untitled1.cpp
    syntax error before `>'
    
    31 C:\Dev-C++\Templates\Untitled1.cpp
    
    ANSI C++ forbids declaration `system' with no type
    
    31 C:\Dev-C++\Templates\Untitled1.cpp
    `int system' redeclared as different kind of symbol
    
    328 C:\DEV-C++\include\stdlib.h
    previous declaration of `int system(const char *)'31 C:\Dev-
    
    C++\Templates\Untitled1.cpp
    initialization to `int' from `const char *' lacks a cast
    
    31 C:\Dev-C++\Templates\Untitled1.cpp
    syntax error before `/'
    i put it in code so it would be easier to read.
    i dont know why a lot of those errors are there. if ya wanna help, please do so!
    Last edited by blasta; 11-13-2002 at 07:41 PM.

  8. #8
    TransparentMember correlcj's Avatar
    Join Date
    Jun 2002
    Posts
    378

    SEE edited with //

    Originally posted by blasta
    ok, here is my program (its pretty crappy, but im just tryin to make something):
    Code:
    #inlcude <iostream>   // include spelled wrong
    
    #include <stdlib.h>
     
    using namespace std;
    //you forgot using namespace std; always a must have i would say.
    
    int main();  //cant use ; after main just int main()
    
    {
    
        int answer;  //variable
        
        cout<<"What is 2+2?";  //Ya betta know that one!
        
        cin>>answer;  //here's where the value goes into our trusty variable, answer
        
        if(answer==4)  //if the user puts in 4, it will be correct.
        
        {
    
        cout<<"You are right. 2+2=4. Very good! You are very smart! Thank you for playing 2+2. Have a nice day."; 
        
        }
    
        else
        
        {
    
        cout<<"You are wrong. Get outta here!";  //This happens if the answer is anything but 2
        
        }
    
        system("PAUSE")/    // you have / istead of ;
    
        return 0;
        
    }
    here are the errors i got (ALL of them, dont bother helping if you don't wanna):
    Code:
    1 C:\Dev-C++\Templates\Untitled1.cpp
    undefined or invalid # directive
    
    7 C:\Dev-C++\Templates\Untitled1.cpp
    parse error before `{'
    
    11 C:\Dev-C++\Templates\Untitled1.cpp
    syntax error before `<'
    
    13 C:\Dev-C++\Templates\Untitled1.cpp
    syntax error before `>'
    
    31 C:\Dev-C++\Templates\Untitled1.cpp
    
    ANSI C++ forbids declaration `system' with no type
    
    31 C:\Dev-C++\Templates\Untitled1.cpp
    `int system' redeclared as different kind of symbol
    
    328 C:\DEV-C++\include\stdlib.h
    previous declaration of `int system(const char *)'31 C:\Dev-
    
    C++\Templates\Untitled1.cpp
    initialization to `int' from `const char *' lacks a cast
    
    31 C:\Dev-C++\Templates\Untitled1.cpp
    syntax error before `/'
    i put it in code so it would be easier to read.
    i dont know why a lot of those errors are there. if ya wanna help, please do so!


    NOTE: Look at the syntax errors/ misspelled, missing items you have. Does this help you better, my friend.

    I hope this helps??
    "Be formless, shapeless, like water... You put water into a cup, it becomes the cup, you put water into a bottle, it becomes the bottle, you put it in a teapot, it becomes the teapot... Now water can flow, or it can crash, be water my friend."
    -Bruce Lee

  9. #9
    Registered User
    Join Date
    Nov 2002
    Posts
    20
    i dont know how i spelled something like { wrong though...

    EDIT
    oops sorry i didnt look at your post well enough, i thought it was just a direct quote. thanx a lot again, it works!!! ill just have to be more careful next time...
    Last edited by blasta; 11-13-2002 at 07:51 PM.

  10. #10
    TransparentMember correlcj's Avatar
    Join Date
    Jun 2002
    Posts
    378

    BTW...

    Highlight the entire code in your program then press and hold alt and hit f8 to auto indent 4 ya! just a hint someone shared with me now i share with you.


    BTW>>your_code

    Code:
    #include <iostream>
    #include <stdlib.h>
    using namespace std;
    
    int main()
    {
    
        int answer;  //variable
        
        cout << "What is 2+2?";  //Ya betta know that one!
        
        cin >> answer;  //here's where the value goes into our trusty variable, answer
        
        if(answer == 4)  //if the user puts in 4, it will be correct.
    		
        {
    		
    		cout << "You are right. 2+2=4. 
    				"Very good!\n"  //dont forget these \n = next line characters
    				"You are very smart!\n" 
    				"Thank you for playing 2+2.\n\n"
    				Have a nice day."; 
    		
        }
    	
        else
    		
        {
    		
    		cout << "You are wrong. Get outta here!";  //This happens if the answer is anything but 2
    		
        }
    	
        system("PAUSE");
    		
    		return 0;
        
    }
    cj
    "Be formless, shapeless, like water... You put water into a cup, it becomes the cup, you put water into a bottle, it becomes the bottle, you put it in a teapot, it becomes the teapot... Now water can flow, or it can crash, be water my friend."
    -Bruce Lee

  11. #11
    TransparentMember correlcj's Avatar
    Join Date
    Jun 2002
    Posts
    378

    You didnt...

    Originally posted by blasta
    i dont know how i spelled something like { wrong though...
    you didnt but you have to look one line ahead or one line behind where the error points to because that may be where the real problem lies. I have no idea why it alarms like that but hey "we just fix em, right?"
    cj
    "Be formless, shapeless, like water... You put water into a cup, it becomes the cup, you put water into a bottle, it becomes the bottle, you put it in a teapot, it becomes the teapot... Now water can flow, or it can crash, be water my friend."
    -Bruce Lee

  12. #12
    Registered User
    Join Date
    Nov 2002
    Posts
    20
    thanx again, it worked

  13. #13
    TransparentMember correlcj's Avatar
    Join Date
    Jun 2002
    Posts
    378

    No Problemo!

    U R welcome!

    See bruces quote below, plz.

    Later, my friend.

    Good Luck, Blasta!
    cj
    "Be formless, shapeless, like water... You put water into a cup, it becomes the cup, you put water into a bottle, it becomes the bottle, you put it in a teapot, it becomes the teapot... Now water can flow, or it can crash, be water my friend."
    -Bruce Lee

  14. #14
    Registered User
    Join Date
    Nov 2002
    Posts
    20

    Re: Re: yet another question ;)

    Originally posted by correlcj
    1st its either this #include <iostream> or #include "iostream.h". I have never seen ..."<iostream.h>" it like this but what you must do is create a header file and link every other .cpp file to you header file like so "header.h"

    I hope this makes sense.

    Good Luck!
    cj
    i know this is said a long time after you posted, but im wondering how do you make a header file?

  15. #15
    TransparentMember correlcj's Avatar
    Join Date
    Jun 2002
    Posts
    378

    Question what program R U using?

    Do you have MVC ++?
    "Be formless, shapeless, like water... You put water into a cup, it becomes the cup, you put water into a bottle, it becomes the bottle, you put it in a teapot, it becomes the teapot... Now water can flow, or it can crash, be water my friend."
    -Bruce Lee

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Alice....
    By Lurker in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 06-20-2005, 02:51 PM
  2. Debugging question
    By o_0 in forum C Programming
    Replies: 9
    Last Post: 10-10-2004, 05:51 PM
  3. Question about pointers #2
    By maxhavoc in forum C++ Programming
    Replies: 28
    Last Post: 06-21-2004, 12:52 PM
  4. Question...
    By TechWins in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 07-28-2003, 09:47 PM
  5. Question, question!
    By oskilian in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 12-24-2001, 01:47 AM