C++ program is giving a too many arguments warning

后端 未结 2 897
故里飘歌
故里飘歌 2021-01-29 16:15

I barely know what I\'m doing, I have this code where I try to solve some simple math:

 #include
 #include
 #include

        
2条回答
  •  一整个雨季
    2021-01-29 16:59

    Corrected code (fixes as pointed out in the comments):

    #include
    //#include // You don't use anything from these headers (yet?)
    //#include
    
    //main()
    int main() // main has to be defiend as an int function
    {
        int n, sum = 0;
        printf("ENTER NUMBER:");
    //  scanf("%i", n);
        scanf("%i", &n); // scanf need the ADDRRESS of variables
        while (n > 0)
        {
            sum += n;
            n--;
        }
    //  printf("\n sum is:", sum);
        printf("\n sum is: %i", sum); // printf needs a format specifier for each variable
        return 0;
    }
    

提交回复
热议问题