Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Nov 17th, 2006, 4:42 AM   #1
sayu
Newbie
 
Join Date: Nov 2006
Posts: 10
Rep Power: 0 sayu is on a distinguished road
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
sayu is offline   Reply With Quote
Old Nov 17th, 2006, 5:14 AM   #2
mrynit
Hobbyist Programmer
 
mrynit's Avatar
 
Join Date: Mar 2006
Location: WA, USA
Posts: 332
Rep Power: 3 mrynit is on a distinguished road
Send a message via AIM to mrynit Send a message via MSN to mrynit Send a message via Yahoo to mrynit Send a message via Skype™ to mrynit
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
__________________
i dont know much about programming but i try to help
mrynit is offline   Reply With Quote
Old Nov 17th, 2006, 5:24 AM   #3
sayu
Newbie
 
Join Date: Nov 2006
Posts: 10
Rep Power: 0 sayu is on a distinguished road
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
sayu is offline   Reply With Quote
Old Nov 17th, 2006, 5:49 AM   #4
grumpy
Programming Guru
 
grumpy's Avatar
 
Join Date: Jun 2005
Location: Adelaide, South Australia
Posts: 1,223
Rep Power: 5 grumpy is on a distinguished road
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.
grumpy is offline   Reply With Quote
Old Nov 17th, 2006, 5:57 AM   #5
mrynit
Hobbyist Programmer
 
mrynit's Avatar
 
Join Date: Mar 2006
Location: WA, USA
Posts: 332
Rep Power: 3 mrynit is on a distinguished road
Send a message via AIM to mrynit Send a message via MSN to mrynit Send a message via Yahoo to mrynit Send a message via Skype™ to mrynit
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
__________________
i dont know much about programming but i try to help
mrynit is offline   Reply With Quote
Old Nov 19th, 2006, 3:11 AM   #6
bl00dninja
Programming Guru
 
bl00dninja's Avatar
 
Join Date: Oct 2004
Location: namespace std
Posts: 1,246
Rep Power: 5 bl00dninja is on a distinguished road
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).
__________________
i put on my robe and wizard hat...

Have you ever heard of Plato, Aristotle, Socrates?...Morons.
bl00dninja is offline   Reply With Quote
Old Nov 19th, 2006, 3:45 AM   #7
grumpy
Programming Guru
 
grumpy's Avatar
 
Join Date: Jun 2005
Location: Adelaide, South Australia
Posts: 1,223
Rep Power: 5 grumpy is on a distinguished road
Quote:
Originally Posted by bl00dninja View Post
try sleep() from <cstdlib> (i think i may be wrong)
You think correctly in this case: you are, indeed, wrong.
grumpy is offline   Reply With Quote
Old Nov 19th, 2006, 3:47 AM   #8
mrynit
Hobbyist Programmer
 
mrynit's Avatar
 
Join Date: Mar 2006
Location: WA, USA
Posts: 332
Rep Power: 3 mrynit is on a distinguished road
Send a message via AIM to mrynit Send a message via MSN to mrynit Send a message via Yahoo to mrynit Send a message via Skype™ to mrynit
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
__________________
i dont know much about programming but i try to help
mrynit is offline   Reply With Quote
Old Nov 19th, 2006, 10:37 AM   #9
Jessehk
The Oblivious One
 
Jessehk's Avatar
 
Join Date: May 2005
Location: Ontario, Canada
Posts: 644
Rep Power: 4 Jessehk is on a distinguished road
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.
__________________
Dr. Zoidberg: [ecstatic] I'm going to a movie... with FRIENDS!
Jessehk is offline   Reply With Quote
Old Nov 20th, 2006, 11:06 AM   #10
v0id
Hobbyist Programmer
 
Join Date: Apr 2006
Posts: 155
Rep Power: 3 v0id is on a distinguished road
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!
__________________
-- v0id
v0id is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Combining languages titaniumdecoy Other Programming Languages 12 Jul 13th, 2006 2:03 PM
Compiling Maverik 6.2 (from C) megamind5005 C 16 May 3rd, 2006 5:41 PM
libraries matko C 1 Jan 22nd, 2006 2:12 PM
Jackpot game zorin Visual Basic 3 Jun 10th, 2005 1:19 PM
airport Log program using 3D linked List : problem reading from file gemini_shooter C++ 0 Mar 2nd, 2005 4:12 PM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 2:12 AM.

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