| | |
four function in maim II
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
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.
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;
1. main() should return an integer. I know it returns 0 if no return is specified, but you should expeclitly return a value anyway.
C++ Syntax (Toggle Plain Text)
system("pause"); } return 0;
>>#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.
•
•
Join Date: Oct 2006
Posts: 7
Reputation:
Solved Threads: 0
I tried all this stuff still didn't work.
•
•
•
•
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.
2. Above is not inside any function.C++ Syntax (Toggle Plain Text)
system("pause"); } return 0;
>>#define PI 3.14159
you should declare this as a const. defines are fround upon in c++ programs.
const float PI = 3.14159;
I allready mentioned this in your other thread :
This isn't in main() nor in another function. Put this before the closing brracket from main(){}
This should be intProd,with a t
This should be intDiff, with a t
Regards Niek
system("pause");
}
return 0;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)
int inDiff(int num1, int num2)Regards Niek
Last edited by niek_e; Nov 29th, 2006 at 3:05 am.
•
•
Join Date: Oct 2006
Posts: 57
Reputation:
Solved Threads: 2
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!!
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! 
C++ Syntax (Toggle Plain Text)
#include <iostream> // needed for Cin and Cout using namespace std; //#define PI 3.14159 // don't need this int intSum(int ,int ); int intDiff(int , int ); int intProd(int , int ); double Quot(int , int ); int main() { int num1; int num2; int s=0; int d=0; int p=0; double q=0.0; cout << " enter first number: \n"; cin >>num1; cout << " enter second number: \n"; cin >> num2; s = intSum(num1,num2); cout << " The sum of two numbers is" << s << "\n"; d = intDiff(num1,num2); cout << " The difference of the two numbers is" << d <<"\n"; p = intProd(num1,num2); cout << "The Product of two numbers is"<< p <<"\n"; q = Quot(num1,num2); cout << " The quoent of two numbers is"<< q <<"\n"; system("pause"); // placed this here, it was at the end of the program return 0; // placed this here, it was at the end of the program } int intSum( int num1, int num2) { int s=0; s = num1 + num2; return s; } //int inDiff(int num1, int num2) // placed a 't' in intDiff int intDiff(int num1, int num2) { int d=0; d = num1 - num2; return d; } //int inProd(int num1, int num2) int intProd(int num1, int num2) // placed a 't' in intProd { int p = 0; p = num1 * num2; return p; } double Quot(int num1, int num2) { double q = 0.0; q = num1 % num2; return q; } // the bit below shouldn't be here, should be at the end of main /* system("pause"); } return 0; */

C++ Syntax (Toggle Plain Text)
#include <iostream> using namespace std; // const double PI = 3.14159; // don't need this int intSum(int, int); int intDiff(int, int); int intProd(int, int); double Quot(int, int); int main() { int num1; int num2; cout << "Enter first number: \n"; cin >> num1; cout << "Enter second number: \n"; cin >> num2; cout << "The sum of two numbers is " << intSum(num1,num2) << "\n"; cout << "The difference of the two numbers is " << intDiff(num1,num2) <<"\n"; cout << "The Product of two numbers is "<< intProd(num1,num2) <<"\n"; cout << "The quoent of two numbers is "<< Quot(num1,num2) <<"\n"; return 0; } int intSum(int num1, int num2) { return (num1 + num2); } int intDiff(int num1, int num2) { return (num1 - num2); } int intProd(int num1, int num2) { return (num1 * num2); } double Quot(int num1, int num2) { return (num1 % num2); }
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.
•
•
Join Date: Oct 2006
Posts: 57
Reputation:
Solved Threads: 2
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
•
•
•
•
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
Here's a quote from 'ere
http://www.research.att.com/~bs/bs_faq2.html#void-main
C++ Syntax (Toggle Plain Text)
In C++, main() need not contain an explicit return statement. In that case, the value returned is 0, meaning successful execution. For example: #include<iostream> int main() { std::cout << "This program returns the integer value 0\n"; }
Last edited by iamthwee; Nov 29th, 2006 at 6:29 pm.
*Voted best profile in the world*
![]() |
Other Threads in the C++ Forum
- Previous Thread: Is this a C++ project?
- Next Thread: currency conversion program error
| Thread Tools | Search this Thread |
Tag cloud for C++
api application array arrays based beginner binary bmp c++ c/c++ calculator char char* class classes code coding compile compiler console conversion convert count data database delete deploy developer display dll dynamiccharacterarray email encryption error file format forms fstream function functions game generator givemetehcodez graph homeworkhelp iamthwee ifstream image input int java lib list loop looping loops map math matrix memory multiple newbie news number numbertoword output pointer problem program programming project python random read recursion recursive reference return rpg simple sorting spoonfeeding string strings struct template templates text tree url variable vector video visual visualstudio win32 windows winsock wordfrequency wxwidgets






