can anyone tell me? DJGPP question

3 views
Skip to first unread message

footybet

unread,
Oct 29, 2005, 5:37:53 AM10/29/05
to C++ Game Programming
I have input the following program from an academic text book
using DJGPP C++
I get the error saying Main() should be int
here is the code - Iknow it is a simple program
but is there a code to set the main function rather than void
Thanks in Advance

#include <iostream.h>
// Define a function which returns true (1) if the parameter character
// is in the ascii range 48 to 57 (ie a digit), false (0) if it is not
int isADigit(char c)
{
if(c >= 48 && c <= 57)
{
return 1;
}
else
{
return 0;
}
}
// main tests the function
void main ( )
{
// declare variables
char buffer[80];
int digit_count;
char answer;
// loop until the user terminates the program
do
{
digit_count = 0;
cout << "Enter a string of characters";
cin >> buffer;
// loop through the string, counting digits
for(int i = 0; buffer[i] != '\0'; i++)
{
if(isADigit(buffer[i]))
{
digit_count++;
}
}
// Display the result
cout << "Total number of digits in string = " << digit_count
<< endl;
cout << "Try another string (Y/N)?";
cin >> answer;
cout << endl;
} while (answer != 'n' && answer != 'N');
}

NoXy

unread,
Oct 29, 2005, 5:52:07 AM10/29/05
to C-Game-Pr...@googlegroups.com
well change to:
int main(){
//and add to end
return 1;

footybet

unread,
Oct 29, 2005, 5:54:30 AM10/29/05
to C++ Game Programming
thanks, I will try it when I get home...

Spy187

unread,
Oct 30, 2005, 6:26:27 PM10/30/05
to C++ Game Programming

jakob lin

unread,
Oct 31, 2005, 2:31:15 AM10/31/05
to C-Game-Pr...@googlegroups.com
why are we doing his homework ???
--
Jakob Lin Mall

jatin makhija

unread,
Feb 9, 2006, 2:02:56 AM2/9/06
to C-Game-Pr...@googlegroups.com
Well, i would rather say that u are taking parameter as a character
but manipulating the integer values can turn you to change the main()
method to int instead of void ,void can be written if u are not returning any
value.
 
think  carefully and respond
 
the messege is turning out to be late but no matter keep asking good ones. thanks for Q.
 
Reply all
Reply to author
Forward
0 new messages