four function in maim II

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Oct 2006
Posts: 7
Reputation: Francis Waldron is an unknown quantity at this point 
Solved Threads: 0
Francis Waldron Francis Waldron is offline Offline
Newbie Poster

four function in maim II

 
0
  #1
Nov 29th, 2006
Here is another shot at it. It all most complier but falls short . still I know it doesn't mean its right. thanks for the help so far.
Attached Files
File Type: cpp fourFunction.ccp.cpp (1.9 KB, 4 views)
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,606
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1490
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is online now Online
Still Learning

Re: four function in maim II

 
0
  #2
Nov 29th, 2006
two problems I can see without even compiling it.

1. main() should return an integer. I know it returns 0 if no return is specified, but you should expeclitly return a value anyway.

  1. system("pause");
  2. }
  3. return 0;
2. Above is not inside any function.

>>#define PI 3.14159
you should declare this as a const. defines are fround upon in c++ programs.

const float PI = 3.14159;
Last edited by Ancient Dragon; Nov 29th, 2006 at 12:22 am.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 7
Reputation: Francis Waldron is an unknown quantity at this point 
Solved Threads: 0
Francis Waldron Francis Waldron is offline Offline
Newbie Poster

Re: four function in maim II

 
0
  #3
Nov 29th, 2006
I tried all this stuff still didn't work.



Originally Posted by Ancient Dragon View Post
two problems I can see without even compiling it.

1. main() should return an integer. I know it returns 0 if no return is specified, but you should expeclitly return a value anyway.

  1. system("pause");
  2. }
  3. return 0;
2. Above is not inside any function.

>>#define PI 3.14159
you should declare this as a const. defines are fround upon in c++ programs.

const float PI = 3.14159;
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 2,965
Reputation: niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute 
Solved Threads: 308
Moderator
Featured Poster
niek_e's Avatar
niek_e niek_e is offline Offline
Cenosillicaphobiac

Re: four function in maim II

 
0
  #4
Nov 29th, 2006
I allready mentioned this in your other thread :

 
system("pause");
} 
return 0;
This isn't in main() nor in another function. Put this before the closing brracket from main(){}
 
cout << " The quoent of two numbers is"<< q <<"\n";
 
//put it HERE and remove the bracket in marked in blue
 
}

int inProd(int num1, int num2)
This should be intProd,with a t
 
int inDiff(int num1, int num2)
This should be intDiff, with a t

Regards Niek
Last edited by niek_e; Nov 29th, 2006 at 3:05 am.
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 57
Reputation: may4life is an unknown quantity at this point 
Solved Threads: 2
may4life may4life is offline Offline
Junior Poster in Training

Re: four function in maim II

 
0
  #5
Nov 29th, 2006
I've commented out your mistakes and placed the correct bits where necessary. I also commented what you had wrong. Its mostly syntax errors, nothing too bad, just keep a eye out for these things. Also, always make sure your main() returns a 0. You had this code, but right down the bottom of your program!!
  1. #include <iostream> // needed for Cin and Cout
  2. using namespace std;
  3.  
  4. //#define PI 3.14159 // don't need this
  5.  
  6. int intSum(int ,int );
  7. int intDiff(int , int );
  8. int intProd(int , int );
  9. double Quot(int , int );
  10.  
  11. int main()
  12. {
  13. int num1;
  14. int num2;
  15. int s=0;
  16. int d=0;
  17. int p=0;
  18. double q=0.0;
  19.  
  20. cout << " enter first number: \n";
  21. cin >>num1;
  22. cout << " enter second number: \n";
  23. cin >> num2;
  24. s = intSum(num1,num2);
  25. cout << " The sum of two numbers is" << s << "\n";
  26.  
  27. d = intDiff(num1,num2);
  28. cout << " The difference of the two numbers is" << d <<"\n";
  29.  
  30. p = intProd(num1,num2);
  31. cout << "The Product of two numbers is"<< p <<"\n";
  32.  
  33. q = Quot(num1,num2);
  34. cout << " The quoent of two numbers is"<< q <<"\n";
  35.  
  36. system("pause"); // placed this here, it was at the end of the program
  37. return 0; // placed this here, it was at the end of the program
  38. }
  39. int intSum( int num1, int num2)
  40. {
  41. int s=0;
  42. s = num1 + num2;
  43. return s;
  44. }
  45. //int inDiff(int num1, int num2) // placed a 't' in intDiff
  46. int intDiff(int num1, int num2)
  47. {
  48. int d=0;
  49. d = num1 - num2;
  50. return d;
  51. }
  52. //int inProd(int num1, int num2)
  53. int intProd(int num1, int num2) // placed a 't' in intProd
  54. {
  55. int p = 0;
  56. p = num1 * num2;
  57. return p;
  58. }
  59. double Quot(int num1, int num2)
  60. {
  61. double q = 0.0;
  62. q = num1 % num2;
  63. return q;
  64. }
  65.  
  66. // the bit below shouldn't be here, should be at the end of main
  67. /*
  68.   system("pause");
  69.   }
  70.   return 0;
  71. */
Also, check this version out. It uses less variables and is cleaner and easier to understand. Study this and see the differences. Then make your decision as which road to take, good luck!
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. // const double PI = 3.14159; // don't need this
  6.  
  7. int intSum(int, int);
  8. int intDiff(int, int);
  9. int intProd(int, int);
  10. double Quot(int, int);
  11.  
  12. int main()
  13. {
  14. int num1;
  15. int num2;
  16.  
  17. cout << "Enter first number: \n";
  18. cin >> num1;
  19. cout << "Enter second number: \n";
  20. cin >> num2;
  21.  
  22. cout << "The sum of two numbers is " << intSum(num1,num2) << "\n";
  23. cout << "The difference of the two numbers is " << intDiff(num1,num2) <<"\n";
  24. cout << "The Product of two numbers is "<< intProd(num1,num2) <<"\n";
  25. cout << "The quoent of two numbers is "<< Quot(num1,num2) <<"\n";
  26.  
  27. return 0;
  28. }
  29.  
  30. int intSum(int num1, int num2)
  31. {
  32. return (num1 + num2);
  33. }
  34.  
  35. int intDiff(int num1, int num2)
  36. {
  37. return (num1 - num2);
  38. }
  39.  
  40. int intProd(int num1, int num2)
  41. {
  42. return (num1 * num2);
  43. }
  44.  
  45. double Quot(int num1, int num2)
  46. {
  47. return (num1 % num2);
  48. }
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 5,273
Reputation: iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold 
Solved Threads: 378
Featured Poster
iamthwee's Avatar
iamthwee iamthwee is offline Offline
Posting Expert

Re: four function in maim II

 
0
  #6
Nov 29th, 2006
>Also, always make sure your main() returns a 0.

Why? Pray tell?
*Voted best profile in the world*
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,606
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1490
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is online now Online
Still Learning

Re: four function in maim II

 
0
  #7
Nov 29th, 2006
Originally Posted by iamthwee View Post
>Also, always make sure your main() returns a 0.

Why? Pray tell?
It is standard convention throughout the IT industry for programs to return 0 when it exits normally, or some other value to indicate an error occurred. This allows other programs to check the status of the program and take appropriate action if necessary.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 57
Reputation: may4life is an unknown quantity at this point 
Solved Threads: 2
may4life may4life is offline Offline
Junior Poster in Training

Re: four function in maim II

 
0
  #8
Nov 29th, 2006
int main() is used to return 0 at the end. This 0 is returned to the Operating system to denote that the function main() - which is the only function called by the operating system and that's why its so special - has completed successfully. Always use int main() and return 0 at the end of it. Dont use void
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 5,273
Reputation: iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold 
Solved Threads: 378
Featured Poster
iamthwee's Avatar
iamthwee iamthwee is offline Offline
Posting Expert

Re: four function in maim II

 
0
  #9
Nov 29th, 2006
Originally Posted by may4life View Post
int main() is used to return 0 at the end. This 0 is returned to the Operating system to denote that the function main() - which is the only function called by the operating system and that's why its so special - has completed successfully. Always use int main() and return 0 at the end of it. Dont use void
No I always use int main, but I don't always write return 0; at the end. It still works, why? Explain.


Here's a quote from 'ere

http://www.research.att.com/~bs/bs_faq2.html#void-main

  1.  
  2.  
  3.  
  4. In C++, main() need not contain an explicit return statement. In that case, the value returned is 0, meaning successful execution. For example:
  5.  
  6. #include<iostream>
  7.  
  8. int main()
  9. {
  10. std::cout << "This program returns the integer value 0\n";
  11. }
Last edited by iamthwee; Nov 29th, 2006 at 6:29 pm.
*Voted best profile in the world*
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 5,273
Reputation: iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold 
Solved Threads: 378
Featured Poster
iamthwee's Avatar
iamthwee iamthwee is offline Offline
Posting Expert

Re: four function in maim II

 
0
  #10
Nov 29th, 2006
Well?
*Voted best profile in the world*
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the C++ Forum
Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC