-
Countdown in Program
Hi,
i am creating a washing machine program and when you select a command for example "wash" it will wash. what i want it to do is when wash is selected cout down to zero and then return to the main screen.
i have the code for the coutdown but i am unsure how to implement it into an if statement.
here is the timer code.
Code:
void wait ( int seconds )
{
clock_t endwait;
endwait = clock () + seconds * CLK_TCK ;
while (clock() < endwait) {}
}
int main2 ()
{
int n;
cout << "Washing...\n";
for (n=10; n>0; n--)
{
printf ("%d\n",n);
wait (1);
}
cout << "WASHING COMPLETE\n";
}
i would like this code to activate for example at this part of the program.
Code:
if (number==1)
{
system("cls");
cout <<"WASHING" <<endl <<endl;
}
Can anyone help how to get it to work?
-
I'mnot sure I understand you but could you not just nest the loop inside the conditional statement.
And why do you use cout and then suddenly printf in the loop?
If you are going to use system then you are making your code Windows only anyway so you might aswell just include Windows.h and then use Sleep(x).
-
http://en.wikipedia.org/wiki/Finite_state_machine
Basically, you have a series of states - Washing, Rinsing, Finished etc and a means of getting between the various states (like an elapsed time, or some event like "no water").
-
maybe i'm missing something but couldn'y you just do
Code:
if (number==1) {
system("cls");
cout <<"WASHING" <<endl <<endl;
int result = main2();
}
also if you declare a function with a return value then...well, you must return a value
Code:
int main2 () {
........
return (1);
}
is it just a CLI/console application?
do you have your menu code done?