'was not declared in this scope' error

前端 未结 5 749
难免孤独
难免孤独 2020-12-01 15:55

So I was writing this simple program to calculate the day of any date using the Gaussian algorithm found here.

#include 
using namespace std;         


        
5条回答
  •  广开言路
    2020-12-01 16:30

    Here

    {int y=((year-1)%100);int c=(year-1)/100;}
    

    you declare and initialize the variables y, c, but you don't used them at all before they run out of scope. That's why you get the unused message.

    Later in the function, y, c are undeclared, because the declarations you made only hold inside the block they were made in (the block between the braces {...}).

提交回复
热议问题