I have a void function that helps me set the time on my arduino clock. I need to use the same function twice - once for the alarm and once for the actual time. The variables I am defining need to equal either alarmHours and alarmMinutes, or hours and minutes. This was my solution:
void setting(int i){
if(i==0){
int mi=alarmMinutes;
int ho=alarmHours;
}else if(i==1){
int mi=minutes;
int ho=hours;
}
//more code later
}
I got an error saying that ho and mi are undefined. I fixed this like this:
void setting(int i){
int mi;
int ho;
if(i==0){
mi=alarmMinutes;
ho=alarmHours;
}else if(i==1){
mi=minutes;
ho=hours;
}
}
This solved the problem. Why couldn't I use the first option if I passed in a 0 or a 1 to the parameters of the function?