943,912 Members | Top Members by Rank

Ad:
  • C Discussion Thread
  • Marked Solved
  • Views: 582
  • C RSS
Nov 9th, 2008
0

simple program problem - need help

Expand Post »
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!
Similar Threads
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
atman is offline Offline
50 posts
since Oct 2008
Nov 9th, 2008
0

Re: simple program problem - need help

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. }
Reputation Points: 118
Solved Threads: 15
Posting Pro in Training
Denniz is offline Offline
428 posts
since Sep 2008
Nov 9th, 2008
0

Re: simple program problem - need help

you can also use the above statement as
void main()
{
........
.......
.....
getch();
}
since in using the void function you need have to use return anything.
Reputation Points: 6
Solved Threads: 9
Junior Poster in Training
ajay.krish123 is offline Offline
90 posts
since Nov 2008

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C Forum Timeline: Binary Operation help.
Next Thread in C Forum Timeline: Counting program executions





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC