Help to find and fix the error in the function.

Error [C ++ Error] Unit1.cpp (11): E2141 Declaration syntax error

//--------------------------------------------------------------------------- #pragma hdrstop #include <iostream.h> #include <conio.h> //--------------------------------------------------------------------------- #pragma argsused int main(int argc, char* argv[]) int sum(int a) { return a + a; } int main() { for (int x=1;x<=10;++x) std::cout<<sqare(x)<<" "; std::cout<<std::endl; std::cout << sum(3, 5) << std::endl; return 0; } //--------------------------------------------------------------------------- 

    3 answers 3

     //--------------------------------------------------------------------------- #pragma hdrstop #include <iostream.h> #include <conio.h> #include <cmath.h> // ΠΈΠ»ΠΈ math.h ΠΈΠ»ΠΈ cmath , ΠΊΠ°ΠΊ Ρ‚Π°ΠΌ Π·Π°Ρ…ΠΎΡ‡Π΅Ρ‚ компилятор. //--------------------------------------------------------------------------- #pragma argsused int sum(int a, int b) { return a + b; } int main(int argc, char* argv[]) { for (int x=1;x<=10;++x) { std::cout<<sqrt(x)<<" "; } std::cout<<std::endl; std::cout << sum(3, 5) << std::endl; return 0; } //--------------------------------------------------------------------------- 

    There is no sqare function. Was meant sqrt? As well as the sum judging by the code, it should be all the same with two parameters. Although not clear

      For the sqrt () function, you need to connect the math.h library, the sum (3, 5) function passes two values, although you have only one declared int sum (int a)

         //Ρƒ вас Π΄Π²Π΅ Ρ„ΡƒΠ½ΠΊΡ†ΠΈΠΈ main() //слСдуСт ΠΏΠΈΡΠ°Ρ‚ΡŒ Ρ‚Π°ΠΊ ... int sum(int ); int main(int argc[], char **argv){...} int sum(int a){ return 2*a; } 
        • Thank you for the answer and good examples. You all helped me very much. I thought about these functions for two days. Everything works. The purpose of the programs was to extract the root from numbers = 1 and <10 and find out their sum - Prog
        • @Prog so it turns out, you need to get the sum of the roots for numbers from 1 to 10? - KoVadim
        • and why is everything so difficult ?? for example, sum is not so difficult to understand an operation as to put it into a separate function. and conio mine is not needed. - sudo97 2:53 pm
        • one
          sum - do you need beginners to train on something? But conio ... This is evident because the institute / school is not yet aware that there is a new standard. A bilder and does not oppose. - KoVadim