Reputation: 17
I'm having a weird issues declaring variable names in C++. When I tried declaring the two variables;
double hoursWorked;
double hourlyWage;
the variable name (hoursWorked
, hourlyWage
) would change colours in my IDE and the program would not compile, citing the names as "unused variables". This issue only happens with those two words when used as identifiers for 'double' variables. I checked the reserved word checklist and nothing seems out of the ordinary in my naming conventions.
I should also note that the variable name will be white (good) right until I type the final 'd' in 'Worked' and the final 'e' in 'Wage', at which it turns blue. This leads me to believe I'm trampling on some kind of keyword, since the "main" in the programs main function is of the same blue colour.
Any help would be appreciated!
Upvotes: 0
Views: 243
Reputation: 326
No errors with this code. Please bear in mind that your unused variables are not errors, simply warnings and your program will still compile and run correctly regardless.
#include <iostream>
int main()
{
double hoursWorked, hourlyWage;
hoursWorked = 2.4;
hourlyWage = 3.5;
std::cout << "Hourly wage holds: " << hourlyWage << "\n";
std::cout << "Hours worked holds: " << hoursWorked << "\n";
return 0;
}
Upvotes: 3