I am trying to figure out how to block out the same input twice or more by a user. For example, the program requires the user to input 3 inputs and not the same inputs. But for now my program still proceeds with choosing the same input. If the user inputs B2
3 times then it chooses it 3 times. The output will be You have chosen these lots: B2 B2 B2
which should not be possible.
my input is array btw. code[3]
.
I want it to be able to read the same input previously and say that it has already been chosen, choose another one as input.
I prefer using strcmp
.
#include <iostream>
#include <iomanip>
#include <string.h>
#include <fstream>
#include <conio.h>
char code[3][10];
for(int a=0; a<3; a++)
{
do
{
cout << "Please enter the lot you are interested in (A1-A7 / B1-B7): ";
cin >> ws;
cin.getline(code[a], 10);
if((strcmp(code[a], "A4") == 0) || (strcmp(code[a], "A6") == 0) || (strcmp(code[a], "B1") == 0)))
{
cout << "ERROR: Sorry! The house you chose has already been booked! \n\n"; // this are for booked lots already from the system
}
else if((strcmp(code[a], "A1") == 0) || (strcmp(code[a], "A2") == 0) || (strcmp(code[a], "A3") == 0) ....
{
cout << "SUCCESS: You have chosen the LOT " << code[a] << endl << endl;
}
else
{
cout << "ERROR: Sorry! The lot you entered is unavailable!" << endl << endl;
// i added strcpy(code[a], "A4"); to trick the system, and it works out.
}
}while((strcmp(code[a], "A4") == 0) || (strcmp(code[a], "A6") == 0) || (strcmp(code[a], "B1") == 0));
}