Rajnish Kaushik Posted January 26, 2014 Posted January 26, 2014 I want to make an programme in c++ (Using Functions) to find the area of squre but i m not able to make it so can someone help me giving some hints my coading for function is int area(int m) int i,area; area=i*i; return(area) } but i m getting error that 1-i is assigned to value that is never used 2-m is assigned to a value that is never used
Sensei Posted January 26, 2014 Posted January 26, 2014 If that's all what you really have, the most visible error is lack of bracket. It should be int area(int m) { And error is obvious - you have uninitialized variable i Shouldn't you multiply by m? int calculate_area(int m) { return(m*m) } Better don't use the same name for variables and function name! Difference between uninitialized variable: int a; and initialized: int a = 0; or int a = b; Initialization means assigning some value to it. Uninitialized variable has random data so using it might result in crashing computer in the worst scenario. 1
Sensei Posted January 26, 2014 Posted January 26, 2014 calculate_area() doesn't mean cal_area()... They have to have the same name for both. You should have functions declared ABOVE main() where they're used. Otherwise you have to make prototype. Prototype for your function would be line int cal_area(int); Get rid of this "int" where is cursor, it's causing error. 1
Strange Posted January 26, 2014 Posted January 26, 2014 You don't need the "int" when you call the function. Just: cout << "Area "<< cal_area(n); 1
Rajnish Kaushik Posted January 26, 2014 Author Posted January 26, 2014 thnx its done yeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee
Sensei Posted January 26, 2014 Posted January 26, 2014 (edited) It won't affect functionality of your code, but better place prototype declaration outside of main() function (before it). In large sources, prototypes are usually put to separate files with .h extension (h = header). Then you can include them in multiple source files. Edited January 26, 2014 by Sensei 1
Rajnish Kaushik Posted January 26, 2014 Author Posted January 26, 2014 A huge thnx to strange and sensai
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now