samedi 10 août 2019

can't find problem in my repeater problem

when I am using my repeater it work fine but when I not type yes 2 times just repeats denied and the loop don't work I want to know the problem of my code I think the problem with kbhit()

I tried everything I know and I am beginner programmer so I don't know match

here is the program it's small

#include <string>
#include <time.h>
#include <conio.h>

using namespace std;
int repeat(int maxx);
void condition(string choice);
void delay (int de);

int main()
{
    while (1){
    delay(1000);
    string choose;
//............................------------------------------...........................;
    cout << "                    repeater program                                       "<<endl;
    cout <<"          \\        ____________________________                                   \n\n";
    cout << "press yes to repeat";
    cin >>choose; // the choice
    condition(choose);
    system ("cls");
    }

}
void delay (int de) // for the delay
{
    int bigde = de + clock();
    while (bigde > clock());


}
void condition(string choice)
{
    if (choice == "yes")
    {
        cout << "choose the number of repeatation" << endl;
        int number;
        cin >> number;
        cout << "press any key to stop";
        delay(1000);
        repeat(number);
    }
    else
    {
       cout << " denied";
       delay(4000);
    }
}




int repeat(int maxx)
{
    int numb = 0;
    while(maxx > numb && !kbhit())
        {cout << "ant thing "; // what you want to repeat
        delay(10);
        numb ++;

 }
  delay(599);
        }


I expected It worked fine, but when I am using it and give wrong input and press many keys it just repeat denied until you close the program but when I removed kbhit() it worked fine.

Aucun commentaire:

Enregistrer un commentaire