I literally initialized them in main, and they dont get called until they are initialized so I don't know why I am getting an error, also fyi my program is not done yet, I still need to write my reset function, and actually call the startTimer() funciton
#include <iostream>
#include <Windows.h>
usingnamespace std;
class Timer {
private:
int numSec;
bool direction;
public:
Timer(int x, bool y)
{
numSec = x;
direction = y;
}
void reset() {
}
void startTimer() {
if (direction = false) {
for (int i = 1; i < lengthUp; i++) {
cout << i << endl;
Sleep(1000);
}
}
else {
for (int i = lengthDown; i > 0; i--) {
cout << i << endl;
Sleep(1000);
}
}
}
};
int main()
{
int lengthUp, lengthDown;
cout << "How long do you want the timer to count up for";
cin >> lengthUp;
cout << "How long do you want the timer to count down for";
cin >> lengthDown;
Timer countUp(lengthUp, false);
Timer countDown(lengthDown, true);
}
To expand on what others have said: lengthUp and lengthDown are defined as local variables in your main function. That means their scope is limited to just that function. They don't exist in any other context, so they don't exist within the Timer::startTimer() method.
In your main function, you pass the values of those variables to the constructor for Timer. However, that doesn't magically create variables with those names inside your Timer class. Timer stores the first value it's given in the variable numSec, so that's the variable you should use inside methods of the class.