Программа зацикливается навсегда при вводе 10 цифр в CIN - PullRequest
0 голосов
/ 12 мая 2018

Можете ли вы помочь мне, ребята? Я абсолютный новичок. Мой код работал нормально, тогда сохраняйте LOOPING FOREVER и никогда не возвращайтесь, иначе cmd завершится с ошибкой «Процесс завершен со статусом -1073741676». Он должен зацикливаться один раз, затем CIN >> снова. Это происходит, когда я вхожу в CIN из 10 цифр >>

#include <iostream>
#include <cstdlib>
#include <ctime>

using namespace std;

class noteAssign {      //This class return "A" if the random number generated is between 1 and 10
    public:
        int x;
        int noteOut(int x){
            if(x>1 && x<10){
                cout << "ITS A" << endl;
                return x;
            }else{
            cout << "IT'S NOT A" << endl;
            return x;
            }
            }
}gonote;

int main()
{
    cout << "Match the note's Hertz!" << endl;
    cout << "Your answer may range from 1 to 20" << endl;
    cout << "Type 0 to quit" << endl;

    int noteIn;                 //No real purpose YET

    do {
        srand(time(0));             //ADDING MULTIPLE RAMDOMIZER FOR WIDER RANDOM RANGE
        int rand1 = 1+(rand()%20); //randomizer 1
        int rand2 = 1*(rand()%20); //randomizer 2
        int hzout = (rand1 * rand2 + rand1 / rand2)%20; //rand 3
        noteAssign gonote;
        cout << gonote.noteOut(hzout) << endl;      //calls the function and gives the parameter
        cin >> noteIn;          //No real purpose YET
    } while(noteIn != 0);       //program quits when you enter "0"

};
...