Thread: help im an idiot

  1. #16
    Registered User
    Join Date
    Feb 2004
    Posts
    127
    Originally posted by Dante Shamest
    Yes, technically, you can. The following code is valid:

    Code:
    int main() {}
    hey
    i wrote a very simple program just to test that
    Code:
    #include<iostream>
    using namespace std;
    int main()
    {
    	int x;
    	cout<<"enter number :\n";
    	cin>>x;
    	cout<<"number is :"<<x<<endl;
    }
    my compiler is Visual Studio 6

    the program runs very well and it works but during compiling it gives errors which is
    E:\Program Files\Microsoft Visual Studio\MyProjects\34\h.cpp(9) : warning C4508: 'main' : function should return a value; 'void' return type assumed
    Linking...

    34.exe - 0 error(s), 1 warning(s)

  2. #17
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >my compiler is Visual Studio 6
    Visual C++ 6 doesn't conform very well to the C++ standard for various good reasons.
    My best code is written with the delete key.

  3. #18
    Registered User
    Join Date
    Mar 2004
    Posts
    220
    Depending on the compiler some will return a value of 0 in main by default and some won't..for instance VC++.

    If your going to use stdlib.h you might as well go the route of system("pause"); but thenagain it isn't needed as most compilers agree with std::cin.get(); Mine however doesn't..for some odd reason..*goes to find out why..<_<*

    Also you might not want to use the entire std namespace..

    It would be more proper to use std::cout << " "; and std::cin >> x; if thats all your going to be using it for.

    The reason your getting this error, is that cout and cin lye in a namespace called 'std'..compilers such as VC++ dont' care if you use std::cout << " "; or cout << " "; All std::cout << " "; does, is tell the compiler that you looking for cout in the namespace std.
    OS: Windows XP Pro CE
    IDE: VS .NET 2002
    Preferred Language: C++.

  4. #19
    Registered User
    Join Date
    Jul 2003
    Posts
    97
    see what u guys do? u guys make a small simple question huge.
    heres a working program. just replace the middle stuff with whatever u need

    Code:
    #include <iostream>
    using namespace std;
    
    int main()
    {
    
    cout << "See how easy it is?!"; // Replace this with whatever code you want
    return 0; // Works fine, stop complaining already!
    }

  5. #20
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >see what u guys do? u guys make a small simple question huge.
    If everyone would just read our minds and do things properly there wouldn't be a problem.
    My best code is written with the delete key.

  6. #21
    Registered User
    Join Date
    Mar 2004
    Posts
    220
    Sry Prelude but I Must steal your >question thing, it's so cool.

    >see what u guys do? u guys make a small simple question huge.

    And not to mention, this doesn't solve his compiler errors.. If we give him more information, and then expound and divulge into it from there, it means that there is a greater possibility to fix his problem. More information = more chance that our answer(s) will fix his problem(s).

    He's looking for a solution as to not only why he's getting an error, but how to fix it. He's not looking for a working program yet. He's looking to build his own working program, thats why he's on this board to learn.

    But ya thats just my 2c.

    Have we solve your problem?
    OS: Windows XP Pro CE
    IDE: VS .NET 2002
    Preferred Language: C++.

  7. #22
    Registered User
    Join Date
    Mar 2004
    Posts
    6

    thanks

    thanks guys but im gonna have to agree with 00bootsy1. all i am is fricken confused. i dont know why the errors are happening i dont know how to fix them because i have tried everything. all i have done lately is copy and paste all your codes and not 1 has worked

    seriously thinking about giving this up before i started. i even tried downloading borland compiler getting same $$$$. but i must admitt for some reason (i have no idea) 00bootsy1 code works

    thanks simon

  8. #23
    Registered User
    Join Date
    Mar 2004
    Posts
    180
    Borland C++ Builder 6.0

    compiles, runs, and works fine.

    Code:
    //---------------------------------------------------------------------------
    
    #include "vcl.h"
    #include <iostream.h>
    #pragma hdrstop
    
    //---------------------------------------------------------------------------
    
    #pragma argsused
    int main(int argc, char* argv[])
    {
    int age;				//Need a variable...
      cout<<"Please input your age: ";	//Asks for age
      cin>>age;				//The input is put in age
      if(age<100)				//If the age is less than 100
      {
         cout<<"You are pretty young!" << endl;     //Just to show it works
      }
      else if(age==100)		//I use else just to show an example
      {
         cout<<"You are old" << endl;		//Just to show you it works...
      }
      else
      {
        cout<<"You are really old" << endl;	//Executed if no other statement is executed
      }
      system("PAUSE");
      return 0;
    }
    //---------------------------------------------------------------------------

  9. #24
    Rabite SirCrono6's Avatar
    Join Date
    Nov 2003
    Location
    California, US
    Posts
    269
    Are you sure you copied all of the code? Because I'm using Dev-C++ 4.9.8.0 too, and my code does work fine on it. So, my guess is that your doing something like not copying all of the code.

    Code:
    #include <iostream>			
    
    using namespace std;
    
    int main()
    {
      int age;
      cout << "Please input your age: ";
      cin >> age;
      if( age < 100 )
      {
         cout << "You are pretty young.";
      }
      else if( age == 100 ) 
      {
         cout << "You are old.";
      }
      else
      {
        cout << "You are really old.";
      }
      cin.get();
      cin.get();
      return 0;
    }
    - SirCrono6
    From C to shining C++!

    Great graphics, sounds, algorithms, AI, pathfinding, visual effects, cutscenes, etc., etc. do NOT make a good game.
    - Bubba

    IDE and Compiler - Code::Blocks with MinGW
    Operating System - Windows XP Professional x64 Edition

  10. #25
    Been here, done that.
    Join Date
    May 2003
    Posts
    1,164
    Originally posted by oobootsy1
    see what u guys do? u guys make a small simple question huge.
    heres a working program. just replace the middle stuff with whatever u need

    Code:
    #include <iostream>
    using namespace std;
    
    int main()
    {
    
    cout << "See how easy it is?!"; // Replace this with whatever code you want
    return 0; // Works fine, stop complaining already!
    }
    The problem with your solution is why yours works and his doesn't. He's learned nothing.
    Definition: Politics -- Latin, from
    poly meaning many and
    tics meaning blood sucking parasites
    -- Tom Smothers

  11. #26
    Registered User
    Join Date
    Mar 2004
    Posts
    180
    okay. He's right, we should explain. Here goes.

    #1

    Code:
    #include
    whenever you include a header file, use a # in front of the 'include'

    if you are the one making the header file, put quotes (" ") around the name, telling the compiuler to look in the main dir for this files. Else, put < > to tell the compiler to look in the main header folder.

    example,
    #include "myfile.h"
    VS
    #include <iostream.h>

    #2
    Code:
    #include <iostream.h>
    This is need for basic "cout" / "cin" functions

    #3
    Code:
    using namespace std;
    Don't recall what it does, but it its 100% needed!

    #4
    Code:
    cout << "Hello world" << endl ;
    this "endl" makes the next line of text spit out onto another line.

    #5
    Code:
    int main(
    int argc, char* argv[] )
    this isn't needed, BUT, its good coding style.

    #6

    putting
    Code:
     return 0;
    not really needed, but you should have it there. Main is jsut another function, and like all functions, it has to return somthing, in this case, '0'

    Code:
    void  main(int argc, char* argv[] }
    {
    cout << "hello world" << endl;
    //no return value, because the funtion is void.
    }
    thats all i can think of off the top of my head, hope this helps some!

    DW
    Last edited by Death_Wraith; 03-21-2004 at 02:35 PM.

  12. #27
    Registered User
    Join Date
    Feb 2004
    Posts
    127
    you dont have to explain every thing .. this can be learned from books and tutorials but when there are errors with someone code we try to tell him what are his errors and explain to him why that is error and how to fix it ... not to explain the whole code line by line

  13. #28
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >we try to tell him what are his errors and explain to him why that is error and how to fix it
    That sounds like what we've been doing all along. You just have to wade through the dozen side conversations (that are all very interesting...sometimes) to find it.

    >not to explain the whole code line by line
    That's good because a line by line commentary is a real pain. I try to do it as little as possible because I have to explain not only what the code is doing, I also must describe what is wrong and why and how to do it right. The end result is usually a rather long post. I don't want to get carpal tunnel before I'm 30.
    My best code is written with the delete key.

  14. #29
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718
    >I don't want to get carpal tunnel before I'm 30.
    ...she says after writing a rather long explanation of stuff dealing with binary trees. Are you saying that it's OK to get it in ~4 years?

    >Visual C++ 6 doesn't conform very well to the C++ standard for various good reasons.
    Just out of curiosity, what are those 'various good reasons'?
    Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

    You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

  15. #30
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >Just out of curiosity, what are those 'various good reasons'?
    Lack of a standard to conform to?
    My best code is written with the delete key.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Idiot spammer.
    By brewbuck in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 03-23-2009, 08:19 PM
  2. Feel Like An Idiot
    By golfinguy4 in forum A Brief History of Cprogramming.com
    Replies: 22
    Last Post: 07-04-2003, 12:45 PM
  3. Screaming idiot - shuttle "photo".
    By adrianxw in forum A Brief History of Cprogramming.com
    Replies: 19
    Last Post: 03-08-2003, 08:44 PM
  4. Replies: 0
    Last Post: 02-24-2002, 09:03 PM
  5. Idiot Canadians
    By Troll_King in forum A Brief History of Cprogramming.com
    Replies: 7
    Last Post: 10-15-2001, 07:35 AM