lundi 13 janvier 2020

Check if the user input has entered a repeated number

So i am still a beginner at this and still practising. Basically i need to make a program that continues to asks the user to enter any number other than 5 until the user enters the number 5.

I have that done but i could't figure out how to check if the user entered a repeating number.For example: 1 2 3 3 - The program should end

#include <iostream>
#include <conio.h>
#include <iomanip>

using namespace std;

int main() {

cout << setw(15) << setfill('*') << "*" << endl;
cout << "Number 5" << endl;
cout << setw(15) << setfill('*') << "*" << endl;

int num;


cout << "Enter a number: ";
cin >> num;

if (num == 5) {
    cout << "\nWhy did you enter 5? :) " << endl;
    _getch();
    exit(0);
}
for (int i = 1; i < 10;i++) {

    cin >> num;

    if (num == 5) {
        cout << "\nWhy did you enter 5? :) " << endl;
        _getch();
        exit(0);
    }
}

cout << "Wow, you're more patient then I am, you win." << endl;
_getch();

}

Aucun commentaire:

Enregistrer un commentaire