-
ok, here it is
Code:
#include <string>
using namespace std;
#include <fstream>
#include <iostream.h>
#include <stdlib.h>
int main()
{
........ int something;
........ string infilename, a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z;
........ ifstream fin;
........ char blah, andy, key[26];
........ for (int word = 0;word < 26;word++) {
............ char key[26] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};
............ blah == key[word];
............ blah = tolower(blah);
............ cout << "Please enter your replacement for character A: \n";
............ cin >> a;
............ something++;
............ cout << "Please enter your replacement for character B: \n";
............ cin >> b;
............ something++;
............ cout << "Please enter your replacement for character C: \n";
............ cin >> c;
............ something++;
............ cout << "Please enter your replacement for character D: \n";
............ cin >> d;
............ something++;
............ cout << "Please enter your replacement for character E: \n";
............ cin >> e;
............ something++;
............ cout << "Please enter your replacement for character F: \n";
............ cin >> f;
............ something++;
............ cout << "Please enter your replacement for character G: \n";
............ cin >> g;
............ something++;
............ cout << "Please enter your replacement for character H: \n";
............ cin >> h;
............ something++;
............ cout << "Please enter your replacement for character I: \n";
............ cin >> i;
............ something++;
............ cout << "Please enter your replacement for character J: \n";
............ cin >> j;
............ something++;
............ cout << "Please enter your replacement for character K: \n";
............ cin >> k;
............ something++;
............ cout << "Please enter your replacement for character L: \n";
............ cin >> l;
............ something++;
............ cout << "Please enter your replacement for character M: \n";
............ cin >> m;
............ something++;
............ cout << "Please enter your replacement for character N: \n";
............ cin >> n;
............ something++;
............ cout << "Please enter your replacement for character O: \n";
............ cin >> o;
............ something++;
............ cout << "Please enter your replacement for character P: \n";
............ cin >> p;
............ something++;
............ cout << "Please enter your replacement for character Q: \n";
............ cin >> q;
............ something++;
............ cout << "Please enter your replacement for character R: \n";
............ cin >> r;
............ something++;
............ cout << "Please enter your replacement for character S: \n";
............ cin >> s;
............ something++;
............ cout << "Please enter your replacement for character T: \n";
............ cin >> t;
............ something++;
............ cout << "Please enter your replacement for character U: \n";
............ cin >> u;
............ something++;
............ cout << "Please enter your replacement for character V: \n";
............ cin >> v;
............ something++;
............ cout << "Please enter your replacement for character W: \n";
............ cin >> w;
............ something++;
............ cout << "Please enter your replacement for character X: \n";
............ cin >> x;
............ something++;
............ cout << "Please enter your replacement for character Y: \n";
............ cin >> y;
............ something++;
............ cout << "Please enter your replacement for character Z: \n";
............ cin >> z;
............ something++;
............ if (something = 26) {
............ cout << "Please input a file (input)" << endl;
............ cin >> infilename;
............ }
........ }
........ if (fin.fail()){
................ cout << "Error - file opening failed" << endl;
................ }
........ while (!fin.eof()) {
............ if (fin.eof())
............ break;
............ for (int word = 0; word < 26; word++) {
............ cout << "Your new message is: \n" << key[word] << endl;
............ }
........ }
........ fin.close();
........ system("PAUSE");
........ return 0;
}
-
this was my assignment..
write a program that encodes the text in a data file using a character array named "key" containing 26 characters; this key is read from the keyboard; the first letter contains the character that is to replace the letter "a" in the data file; the second letter contains the letter that is to replace the letter "b" in the data file; and so on; assume that all punctuation is to be replaced by spaces; check to be sure that the key does not map two different characters to the same one during the encoding
and the second part to it is...
write a program which decodes the file that is the output of Problem 27; assume that the same integer key is read from the keyboard by this program and is used in the decoding steps; note that you will not be able to restore the punctuation characters
-
if (something = 26)
That should be ==
= is the assignment operator
== is boolean equals
Also, you're putting too much into that loop. For instance, the initialization of key should only happen once.
-
Uh... you don't even try to read it in. Just use .
-
ok, thanks, im trying that now... and joshdick.. im trying to figure out what you mean by 'the initialization of key should only happen once. '
-
I'd recommend simply inputting a 26 char string, or if you wish to enter them individually, create a loop to input each char. Hard coding all that is...well messy.
-
ugh... it goes down asking for the replacement like it's supposed to and then it asks for the input file and then it asks for the replacement letters again
-
well, seeing as how i dont know how to do i 26 char string (i haven't been taught) it's kinda hard. i've been trying to do one this whole time, but... im guessing at how to do it.
-
If I wanted 10 integers from a user, I'd do like so:
Code:
const int MAX = 10;
int a[MAX];
for(int i=0; i < MAX; ++i)
{
cout << "Enter an integer: ";
cin >> a[i];
}
Notice how I only need to write the code to input an integer once even though I want to get 10 integers. As a matter of fact, if I wanted 1000 integers, I need only to change MAX to 1000 rather than hard-code 990 more lines of code. Do you see that now?
-
OOOOHHHHH.... ok, i get it... thank you, see.. that was never explained to me before... lol
-
You're already using filehandling and you have not yet learned how to use strings or char arrays?
-
Yeah, well, my prof never really explained anything... the only reason i know how to do the file opening is because someone else showed me how to do it...
-
the only question i have about what the one integer thing is... how do i get the program to ask for the specific replacements of the letters, like "replacement for a: " "replacement for b: ", etc...
-
I'm not quite following the program logic, but it looks like you need a sub loop.
For a given string, you could have something like:
Code:
// I think key is the right string
for(int current = 0; current < SIZE; current++)
{
cout << "Enter replacement for " << key[current] << ": ";
cin >> key[current];
}
Again, I'm not quite following the logic in your code, so that may not be helpful.
-
hm, the mystring thing is kind of confusing me, i think that's what i need, but i'm not completely sure what the mystring is equal to