Hey guys ...I'm in Computer science class that i need for my engineering major. We went over basics of computer science, and below is the assignments that our professor assigned us. I've really tried hard to understand it but i could nt figure out whats wrong with it.
//* Write a C++ program that creates a list of letters that will *
//* be used to encode a message according to the following rule: *
//* *
//* 1. Input a WORD *
//* 2. Remove all repeating letters to form the modified WORD *
//* 3. Place the modified WORD at the beginning of the array *
//* 4. Fill the remainder of the list with any letters of the *
//* alphabet that were not used in the WORD working from A to *
//* Z. (Your list should have all 26 letters of the alphabet *
//* *
//* EXAMPLE: If the user entered HELLO *
//* the modified WORD would become HELO *
//* *
//* and the list would become: *
//* HELOABCDFGIJKMNPQRSTUVXYZ *
//* *
//* NOTE: The list must be stored in an array of CHARacters.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
|
#include<iostream>
using namespace std;
int main()
{
char a;
int b = 0;
char word[4] = "\0";
char alphabet[27] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
char code[27];
cout << "Please enter a word:" << endl;
cin >> word;
for (int i = 0; i<3; i++)
{
if (word[i] == word[i - 1])
{
a = word[i];
word[i] = word[i + 1];
}
code[i] = word[i];
b++;
}
for (int o = 0; o<27; o++)
{
if (alphabet[o] == word[1] || alphabet[o] == word[2] || alphabet[o] == word[3] || alphabet[o] == word[0])
{
o++;
}
code[b] = alphabet[o];
b++;
}
cout << code;
return 0;
}
|
AND PLEASE IF YOU CAN'T HELP DONT LEAVE NEGATIVE COMMENTS!! THANK YOU!!