Oct 6, 2014 at 9:44pm UTC
what do expecte as a result ?
please exemples
Oct 6, 2014 at 9:57pm UTC
the origonal text typed in
Oct 7, 2014 at 2:33am UTC
You can simply use two arrays one for the original word the second for the coded word
Oct 8, 2014 at 7:37pm UTC
I don't know how to use arrays, I only added the decoder onto the program. I am still new at c++
Oct 8, 2014 at 8:16pm UTC
Your variable char user[100] , is an array. If you don't know how to use them, look it up, Google it, or there is a great resource on this website.
Oct 8, 2014 at 10:07pm UTC
ok bu it still doesn't work
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 35
#include <iostream>
#include <string>
using namespace std;
int main(void ) {
char user[100],ch,userout[100];
int counter=0,cntr;
int i;
cout<<"Enter Word\nNo Spaces! \n> " ;
cin >> user;
cout<<"Enter move count\n1-25 only\n> " ;
cin >>counter;
cntr=counter;
while ( user[i] != '\0' ){
ch = user[i];
if ( ch >= 97)
user[i] = (user[i] + counter - 97) % 26 + 97;
else user[i] = (user[i] + counter - 65) % 26 + 65;
i++;}
cout<<endl<<user<<" <Here is the encoded output\n\n" ;
counter=26-cntr;
userout[i]=user[i];
while ( user[i] != '\0' ){
ch = user[i];
if ( ch >= 97)
userout[i] = (user[i] + counter - 97) % 26 + 97;
else userout[i] = (user[i] + counter - 65) % 26 + 65;
i++;}
cout<<endl<<userout<<" <Here is the decoded output\n\n" ;
}
it crashes after this:
userout[i]=user[i];
Last edited on Oct 8, 2014 at 10:15pm UTC
Oct 8, 2014 at 10:37pm UTC
instead of a while loop, try a for loop like
for (int i = 0;i >= user.size(); i++)
Oct 8, 2014 at 10:39pm UTC
Line 14: error: request for member 'size' in 'user', which is of non-class type 'char [100]'
Line 23: error: request for member 'size' in 'user', which is of non-class type 'char [100]'
Last edited on Oct 8, 2014 at 10:41pm UTC
Oct 8, 2014 at 10:50pm UTC
Use the size of the array instead of "user.size()" as arrays don't have size() methods. Also you will want strictly less than rather than greater than or equal to.
for (int i = 0; i < 100; ++i)
Nov 6, 2014 at 4:06am UTC
@jasonwynn10
I hadn't really looked at your program earlier, so never commented on it. Anyway, it intrigued me, so I fiddled with it a bit. Here's what I came up with.
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 35 36 37 38
#include <iostream>
#include <string>
using namespace std;
int main()
{
char user[100] = {' ' },ch,userout[100] = {' ' };
int counter=0,cntr;
int i=0,a=0;
cout<<"Enter Word\nNo Spaces! \n> " ;
cin >> user;
cout<<"Enter move count\n1-25 only\n> " ;
cin >>counter;
cntr=counter;
do
{
ch = user[i];
if ( ch >= 97)
user[i] = (user[i] + counter - 97) % 26 + 97;
else
user[i] = (user[i] + counter - 65) % 26 + 65;
i++;
} while ( user[i] != '\0' );
cout<<endl <<user <<" <Here is the encoded output\n\n" ;
counter=26-cntr;
do
{
ch = user[a];
if ( ch >= 97)
userout[a] = (user[a] + counter - 97) % 26 + 97;
else
userout[a] = (user[a] + counter - 65) % 26 + 65;
a++;
}while ( user[a] != '\0' );
cout<<endl<<userout<<" <Here is the decoded output\n\n" ;
return 0;
}
I changed your while's, to a do/while to stop the userout value having a smiley face symbol at the end. Anyway, I hope this is what you were wanting as results in your program.
Last edited on Nov 6, 2014 at 5:44am UTC
Nov 17, 2014 at 1:14am UTC
thanks, now all I need to do is be able to do this with full sentences and output it into an encoded .txt file and a decoced .txt file.
Nov 17, 2014 at 1:21am UTC
how can I get this to work with sentences? I also need to get a proper text output to the file
code:
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 35 36 37 38 39 40 41 42 43 44 45 46
#include <iostream>
///#include <string>
#include <fstream>
using namespace std;
int main()
{
char user[100] = {' ' },ch,userout[100] = {' ' };
int counter=0,cntr;
int i=0,a=0;
cout<<"Enter Word\nNo Spaces! \n> " ;
cin >> user;
cout<<"Enter move count\n1-25 only\n> " ;
cin >>counter;
cntr=counter;
do
{
ch = user[i];
if ( ch >= 97)
user[i] = (user[i] + counter - 97) % 26 + 97;
else
user[i] = (user[i] + counter - 65) % 26 + 65;
i++;
} while ( user[i] != '\0' );
cout<<endl <<user <<" <Here is the encoded output\n\n" ;
counter=26-cntr;
ofstream myfile;
myfile.open ("encoded.txt" );
myfile << user[i];
myfile.close();
do
{
ch = user[a];
if ( ch >= 97)
userout[a] = (user[a] + counter - 97) % 26 + 97;
else
userout[a] = (user[a] + counter - 65) % 26 + 65;
a++;
}while ( user[a] != '\0' );
cout<<endl<<userout<<" <Here is the decoded output\n\n" ;
myfile.open ("decoded.txt" );
myfile << userout[a];
myfile.close();
return 0;
}
Last edited on Nov 17, 2014 at 1:27am UTC
Nov 19, 2014 at 4:18am UTC
@jasonwynn10
Sorry, I won't be able to help out.
Last edited on Nov 26, 2014 at 4:12am UTC