Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   C++ (http://www.programmingforums.org/forum15.html)
-   -   function errors (http://www.programmingforums.org/showthread.php?t=11914)

sayu Nov 17th, 2006 5:42 AM

function errors
 
hello
can any body how to correct this program
:

#include<iostream>
#include<conio.h>
#include<dos.h>
using namespace std;
void main()
{
    char nm[25];
    cout<<"Enter your name: "<<endl;
    cin>>nm;
    for(int i=0;i<25;i++)
    {
            cout.write(nm,i);
              delay(100);
    }
   
    getch();
}


The errors are
'main must return int'
'delay' function undeclared

Iam using DevCpp iam new to it before i was using Turbo C++
please anybody help me

mrynit Nov 17th, 2006 6:14 AM

the last statment in main should be "return 0;"

delay is a function with in dos.h and if the compiler could not find dos.h it should have said so. im not sure why it does not like the delay function. what OS are you trying to compile this on?

search for dos.h and delay for more help

sayu Nov 17th, 2006 6:24 AM

I am using Windows XP and my compiler is Dev C++
and does a void function return a value ?
and why does delay function doesn't work

grumpy Nov 17th, 2006 6:49 AM

The error "main must return int" is fairly self-explanatory. Change your definition of main() so it returns int rather than void. The C and C++ standards require compilers to support main() that returns int. While returning void is not disallowed, there is no requirement for any compiler to allow it.

The delay() function, like the <dos.h> and <conio.h> header files, are implementation specific --- they are not specified in the C/C++ standards, but some compilers support them as an extension. In other words, they are supported by some compilers/libraries but not others. dev C++ is obviously a compiler that does not support the delay() function.

mrynit Nov 17th, 2006 6:57 AM

dev-C++ does not support the function delay with in dos.h

http://cboard.cprogramming.com/archi...hp/t-8593.html

do some searching on the topic. you will need to make your own delay function or swtich OS or compiler

bl00dninja Nov 19th, 2006 4:11 AM

yeah, main must return an int. change it from void to int.

try sleep() from <cstdlib> (i think i may be wrong)

yeah, this is the gay shit we have to do.

you're using unstandardized crap. you get unstandardized results (like compiler errors).

grumpy Nov 19th, 2006 4:45 AM

Quote:

Originally Posted by bl00dninja (Post 119292)
try sleep() from <cstdlib> (i think i may be wrong)

You think correctly in this case: you are, indeed, wrong.

mrynit Nov 19th, 2006 4:47 AM

if you need to creat a delay use the system timer with a loop. there are plenty of examples of delay loops, google for them

Jessehk Nov 19th, 2006 11:37 AM

I think this is an example where at least one of those errors was extremely self-explanatory.

Quote:

'main must return int'
Part of programming with C and C++ involves using your head and actually reading error messages. In this case, I think the solution (change the declaration of main() to return int) is quite obvious.

v0id Nov 20th, 2006 12:06 PM

Pertaining to the delay-function:
I would implement the "delay"-function in my C++ code like this...
:

#if __linux__
    #include <unistd.h>
    #define delay(x) sleep(x)
#elif _WIN32
    #include <windows.h>
    #define delay(x) Sleep(x * 1000)
#else
    #define delay(x) std::cout << "Unknown OS" << std::endl;
#endif

Only know how to do it in Windows and Linux, sorry Other-OS-users!


All times are GMT -5. The time now is 1:21 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC