simple program problem - need help

Thread Solved

Join Date: Oct 2008
Posts: 48
Reputation: atman is an unknown quantity at this point 
Solved Threads: 0
atman atman is offline Offline
Light Poster

simple program problem - need help

 
0
  #1
Nov 9th, 2008
Hello.,
Im learning C online, and one of the examples from the internet is this:

  1. #include <stdio.h>
  2.  
  3. int CalcVolume (int length, int width, int height);
  4.  
  5. void PrintIt (int vol);
  6.  
  7. void main()
  8. {
  9. int volume1, volume2;
  10. int x = 8, y = 15, z = 20;
  11. volume1 = CalcVolume (10, 20, 30);
  12. PrintIt (volume1);
  13. volume2 = CalcVolume (x, y, z);
  14. PrintIt (volume2);
  15. }
  16.  
  17. /* end of main */
  18.  
  19. int CalcVolume (int length, int width, int height)
  20.  
  21. {
  22.  
  23. int vol;
  24. vol = length * width * height;
  25. return vol;
  26. }
  27. /* end of CalcVolume */
  28.  
  29. void PrintIt (int vol)
  30. {
  31. printf("The volume is: %d\n", vol);
  32. }


but when im trying to compile it sais

ch5m.c: In function ‘main’:
ch5m.c:9: warning: return type of ‘main’ is not ‘int’

is there an error in the exesize?

Thanx!
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 429
Reputation: Denniz is on a distinguished road 
Solved Threads: 15
Denniz's Avatar
Denniz Denniz is offline Offline
Posting Pro in Training

Re: simple program problem - need help

 
0
  #2
Nov 9th, 2008
Some C compiler will give you a warning when your main function does not return an integer.

In this case, do the following changes to the main function:
  1. int main()
  2. {
  3. ......
  4. ......
  5. return 0;
  6. }
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 90
Reputation: ajay.krish123 is an unknown quantity at this point 
Solved Threads: 8
ajay.krish123 ajay.krish123 is offline Offline
Junior Poster in Training

Re: simple program problem - need help

 
0
  #3
Nov 9th, 2008
you can also use the above statement as
void main()
{
........
.......
.....
getch();
}
since in using the void function you need have to use return anything.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC