hi every one
this is the Project requirements
i did the first three things
but i have problme with number 4


You are hired by an electronics company aiming to build microwaves. You are asked to develop an
application that simulates the work of these microwaves. Consider the following specifications:
1. The program should ask the user to specify the cooking time. The user enters it in minutes and
seconds.
2. During the cooking time the program should output a star character every half a second to show
that the cooking is in process.
3. A timer counts down one second at a time. Once the time expires, the program should output
the text message “Done!”.
4. The user should be able to stop the cooking process at any time by entering the character “S”.
He/She may enter a new time.

#include <iostream>
#include <windows.h>

using namespace std;

int main()
{
    int  m,s,t;
    cout<<"enter the munites :";
    cin>>m;
    m=m*60;
    cout<<"enter the seconds :";
    cin>>s;
    s=s+m;
    t=s*2;
    while(t>0)
    {cout<<"*";
     Sleep(500); 
     t--;
     }
     cout<<"DONE !";
     getchar();getchar();
    return 0;
}

Edited 6 Years Ago by m7md.is: n/a

In standard C++ you can't. If your compiler is one of those that has enhancements, there may be a way, but it's non-standard and therefore not recommended.

>In standard C++ you can't. If your compiler is one of those that has enhancements,
>there may be a way, but it's non-standard and therefore not recommended.

I can only assume you were running on autopilot and didn't proofread your post, because that's just stupid.

If there's a standard alternative, non-standard solutions aren't recommended. But if there's not a standard alternative, you don't have a choice if you want to implement the feature. Are you suggesting that the OP not do what he wants at all because it can't be done with standard C++?

I suppose you're right. What I mean -- now that you've lambasted me :icon_wink: is that sonce the functionality requires nonstandard techniques, without knowing what the instructor had in mind (taught) we will very possibly come up with a solution that either cannot be done with the compiler in use or is too advanced and uses functions that are unacceptable to the instructor. IOW, we haven't enough information to suggest a nonstandard implementation. ne?

He has #include <windows.h> , so I believe we can safely assume some things about his operating environment.

On Windows, to wait for an event with a timer, use WaitForSingleObject() with the console input handle specified as the signal object. You'll need to use GetStdHandle().

bool countdown( int& seconds )
  // Displays a countdown timer from 'seconds' downto zero.
  // Returns true if the countdown made it to zero.
  // Returns false if the user pressed a key (which still needs to be read).
  // After the countdown returns, 'seconds' indicates how many seconds still remain to be counted.
  {
  HANDLE hStdIn = GetStdHandle( STD_INPUT_HANDLE );

  cout << "Press any key to abort the countdown.\n";
  for (; seconds; seconds--)
    {
    cout << "\r  " << n << flush;
    if (WaitForSingleObject( hStdIn, 1000 ) == WAIT_OBJECT_0)   // 1 second == 1000 ms
      {
      // The standard input object was signalled, meaning that input is waiting.
      return false;
      }
    }
  // The countdown hit zero. Display that and return success.
  cout << "\rDone!\n";
  return true;
  }

By the way, you should be using ReadConsoleInput() instead of getch()/getchar()/variants.

Also, I just gave you are really big bone. Keep in mind that it is not the whole solution to your homework problem. You still must understand what it is doing and use it properly.

As a hint, your program should be working in a loop to read key presses from the user, and only use the countdown if the user starts the microwave timer.

Hope this helps.

thanks every one
i solved it

and here's what i did

for (int i=1;i<=2*t;i++)
     {
     if (GetAsyncKeyState(0x53)) // when user press S exit 
      break ;
      
      Sleep(500);
      cout<<"*";
      }
     cout<<"\nDone!... "<<endl;

then i had to add a do while loop in the main function.

Edited 6 Years Ago by m7md.is: n/a

This question has already been answered. Start a new discussion instead.