'I keep getting this error: expected primary-expression before 'int'
I am trying to solve this exercise on Exercism website. The exercise is about finding the leap year. I have two files, main one and the header file.
The main one:
#include "leap.h"
int main (){
leap::is_leap_year(int year);
}
The header file:
#if !defined(LEAP_H)
#define LEAP_H
#include <iostream>
#include <string>
namespace leap {
bool is_leap_year(int year) {
bool status=1;
if (((year%4 == 0)&& (!(year%100==100))) || ((year%100==0)&&(year%400==0))){
return status;
}
else{
status = 0;
return status;
}
}
}
#endif // LEAP_H
Whenever I run this code I keep getting this error: expected primary-expression before 'int'
If I removed int from
leap::is_leap_year(int year);
I will get this error: 'year' was not declared in this scope
Solution 1:[1]
Learn about the differences between function declaration, definition and call. As for your question what you're doing wrong here is that you're not passing any value to your function which it expects. Instead you're just declaring an int and hence the error. Declare and initialise the value before passing it to the function.
int year; //declare before using it
year = 20;
leap::is_leap_year(year); //passing a value
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | avm |
