0

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!

6
  • 1
    You should probably show us your code as a minimal, complete, verifiable example (stackoverflow.com/help/mcve). Also since this seem to be dependent on the behavior of your IDE you should tell which one you use (and which compiler you use). Unused variables are perfectly legal in C++ so that should only be a compiler warning. Commented May 18, 2016 at 5:08
  • 1
    The error is quite explicit about the variables are unused. So use them before you try to compile. Maybe assigning a value will help? Commented May 18, 2016 at 5:08
  • I tried to use them and no error occurred. please show us your code. Commented May 18, 2016 at 5:11
  • 2
    @programBABYlover Put the code in the question, not in comments. Commented May 18, 2016 at 5:21
  • 3
    It's really not a problem. You have a program that declares two variables and does nothing. Your IDE is letting you know this might be a problem in realtime. You haven't finished your program yet. You haven't compiled. Unless it's set to treat warnings as errors, this will be fine. Also, please keep your language clean in here. Commented May 18, 2016 at 5:22

1 Answer 1

3

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;
}
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.