Hi!
This program asks to
Read, from the keyboard, a sequence of le
tters (uppercase or lowercase) and save the
corresponding uppercase letter in
to a vector of characters (
vector<char>
) until the user enters the
character "." (period), which should not be inserted in
to the vector; characters other than letters or
characters that have already been typed previous
ly should not be inserted into the vector.
Present the resulting vector on the screen,
using the format shown in the example.
Example:
LETTER or "." ? r
LETTER or "." ? T
LETTER or "." ? 2
// invalid character; it not inserted into the vector
LETTER or "." ? t
// repeated letter; it not inserted into the vector
LETTER or "." ? P
LETTER or "." ? .
VECTOR: [ R T P ]
#include <iostream>
#include <ctime>
#include <ctype.h>
#include <vector>
using namespace std;
char* UCASE(char s[256]){
for(int i=0;s[i]!='\0';i++)
{
s[i]=toupper(s[i]);
}
return s;
}
int isletter(char s)
{
int i;
if (isalpha(s))
{i =1;}
else
{i=0;}
return i;
}
int main(){
char letter[256];
char ter;
ter = atoi(letter);
char end = '.';
vector<char> v;
do
{cout << "LETTER OR '.' ? ";
cin >> letter;
char finletter;
finletter = atoi(UCASE(letter));
if ( !(find(v.begin(), v.end(), finletter) !=v.end()) && isletter(ter)==1)
{
v.push_back(finletter);
};
} while (ter!=end);
{ cout << "VECTOR: [ ";
for (size_t n = 0; n < v.size(); n++)
cout << v[ n ] << " ";
cout << " ]" << endl;}
return 0;
};
The output is asking correctly for the letters, but when putting '.' it continues to answer for a letter instead of displaying the vector.
I've tried just while(ter!='.') and then i did it with do while but it didn't resolve anything.
Can you help?