I have tried writing a code which takes two numbers from the user and calculates their square root then the roots are added up to return the sum. The program is coming out with loads of errors. any help will be appreciated. Thanks
#include<iostream>
#include<cmath>
float main()
{
using namespace std;
float m1,m2,m3,m4,m5;
cin >> m1 >> m2;
m3=rooter(m1);
m4=rooter(m2);
cout << "The square root of the two provided no is " << m3 <<"and" << m4
cout <<"respectively" <<endl;
m5=additioner(m1,m2);
cout <<"The sum of above numbers is" << m5 << endl;
system("pause");
return 0;
}
float main() That's a new one, main should return int
As for the errors they are probably coming from you not having a semi colon on this line cout << "The square root of the two provided no is " << m3 <<"and" << m4 It probably mentioned that when you tried to compile. I would also advise against using system("anything"); as it can leave holes in security and is pretty heavy. There are much better ways to keep the console open if that is what you are trying to do. http://www.cplusplus.com/forum/beginner/1988/
Forgot to mention this you need to prototype your functions before main. So you would copy the first line of the function and put that before the main function with a semi-colon at the end for example:
1 2 3 4 5 6 7
float rooter(float x); //<---prototype
//the prototype doesn't need to have the parameter names but the type is a must
//float rooter(float) <--- so this would work also
int main()
{
...
}
Also, please put code tags around your code. Either edit and press the <> button or type [ code] before and [/code] after (without the space)
TL;DR
3:12: error: '::main' must return 'int' In function 'int main()'
: 8:13: error: 'rooter' was not declared in this scope
11:1: error: expected ';' before 'cout'
12:20: error: 'additioner' was not declared in this scope
Put only one instance of usingnamespace std; after you prototype your functions. You can remove them from the functions, and in main().
You declared float ad(float) with one float variable, but you're sending two. Add another float in the declaration, so it matches what is being called.