![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Nov 2006
Posts: 10
Rep Power: 0
![]() |
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 |
|
|
|
|
|
#2 |
|
Hobbyist Programmer
|
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 |
|
|
|
|
|
#3 |
|
Newbie
Join Date: Nov 2006
Posts: 10
Rep Power: 0
![]() |
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 |
|
|
|
|
|
#4 |
|
Programming Guru
![]() Join Date: Jun 2005
Location: Adelaide, South Australia
Posts: 1,223
Rep Power: 5
![]() |
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. |
|
|
|
|
|
#5 |
|
Hobbyist Programmer
|
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 |
|
|
|
|
|
#6 |
|
Programming Guru
![]() Join Date: Oct 2004
Location: namespace std
Posts: 1,246
Rep Power: 5
![]() |
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. |
|
|
|
|
|
#7 |
|
Programming Guru
![]() Join Date: Jun 2005
Location: Adelaide, South Australia
Posts: 1,223
Rep Power: 5
![]() |
|
|
|
|
|
|
#8 |
|
Hobbyist Programmer
|
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 |
|
|
|
|
|
#9 | |
|
The Oblivious One
Join Date: May 2005
Location: Ontario, Canada
Posts: 644
Rep Power: 4
![]() |
I think this is an example where at least one of those errors was extremely self-explanatory.
Quote:
__________________
Dr. Zoidberg: [ecstatic] I'm going to a movie... with FRIENDS! |
|
|
|
|
|
|
#10 |
|
Hobbyist Programmer
Join Date: Apr 2006
Posts: 155
Rep Power: 3
![]() |
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
__________________
-- v0id
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
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 |