This program was really pain for me to do it but anyways my program must do the following steps:
1. promote the user for 12 characters.
2. check conditions of the 12 characters are the following:
a. The digits 4 and 5 must appear at least once.
b. Either the digit 8 and 9 must appear at least once.
c. The only valid letters are A,L,P,R,T,V,W, and X.
d. Each four-character subsequence (1-4, 5-8, 9-12) must contain at least one digit and at least one letter.
3. sends am error message if the code doesn't follow all the condition.
4.store the code into an array
5. print the code from the menu
my problem:
1. In my code my program doesn't send an error message when I enter the wrong code that doesn't follow the conditions.
2. In my code my program doesn't print the code that follows the conditions from the menu interface.
anyone knows what's the wrong in the code ?
Code:
#include <iostream>
#include <cctype>
#include<string>
#include <stdio.h>
#include <stdlib.h>
using namespace std;
void newCode();
string billy [12];
int main()
{
string billy [12];
int tester;
while((tester >= 1) || (tester < 4))
{
cout << "select one of these options\n";
cout << "(1) Insert a new code\n";
cout << "(2) Print the data\n";
cout << "(3) Exit the program\n";
cin >> tester;
if(tester==1)
newCode();
else if (tester==2)
for (int i=0; i<13; i++)
{
cout << billy[i] << endl;
}
else if (tester==3)
break;
else
cout << "ERROR!!! You must choose one of the options from 1 to 3";
}
return 0;
}
void newCode()
{
string serial_number;
int length;
size_t found,found2,found3,found4;
cout<< "please enter a serial number of 12 characters:";
cin >> serial_number;
length = serial_number.length();
std::string mystr = serial_number;
string str1 ("4");
string str2 ("5");
string str3 ("8");
string str4 ("9");
/* string str5 ("A");
string str6 ("L");
string str7 ("P");
string str8 ("R");
string str9 ("T");
string str10 ("V");
string str11("W");
string str12("X");
found= serial_number.find(str1);
found2= serial_number.find(str2);
found3= serial_number.find(str3);
found4= serial_number.find(str4);
/* found5= serial_number.find(str5);
found6= serial_number.find(str6);
found7= serial_number.find(str7);
found8= serial_number.find(str8);
found9= serial_number.find(str9);
found10= serial_number.find(str10);
found11= serial_number.find(str11);
found12= serial_number.find(str12)*/
if (length!=12 )
cout << "The code you have entered cannot be processed because the code must 12 characters exactly";
else if ((found!=string::npos) && (found2!=string::npos))
if ((found3!=string::npos) || (found4!=string::npos))
for(int i = 0; i< 4; i++)
{
if ((mystr[i] == 'A') || (mystr[i] == 'L') || (mystr[i] == 'P') || (mystr[i] == 'R') || (mystr[i] == 'T') || (mystr[i] == 'V')||(mystr[i] == 'W')||(mystr[i] == 'X'))
for(int i = 4; i< 7; i++)
{
if ((mystr[i] == 'A') || (mystr[i] == 'L') || (mystr[i] == 'P') || (mystr[i] == 'R') || (mystr[i] == 'T') || (mystr[i] == 'V')||(mystr[i] == 'W')||(mystr[i] == 'X'))
for(int i = 7; i< 11; i++)
{
if ((mystr[i] == 'A') || (mystr[i] == 'L') || (mystr[i] == 'P') || (mystr[i] == 'R') || (mystr[i] == 'T') || (mystr[i] == 'V')||(mystr[i] == 'W')||(mystr[i] == 'X'))
for(int i=0; i<length;i++)
{
billy[i]=mystr[i];
}
else
cout << "You are mising one or more of the following:\n";
cout << " 1. The digits 4 and 5 must appear at least once.\n";
cout << " 2. Either the digit 8 and 9 must appear at least once.\n";
cout << " 3. The only valid letters are A,L,P,R,T,V,W, and X.\n";
cout << " 3. Each four-character subsquence (1-4, 5-8, 9-12) must contaon at least one digit and at least one letter.\n";
}
}
}
}