so here is my code. My getlines for the strings keyword and phrase at lines 44 and 79 respectively don't work. Please help!!! -
#include <cstdlib>
-
#include <string>
-
#include <iostream>
-
#include <fstream>
-
using namespace std;
-
string removeAllWhite( string eric)
-
{
-
-
int strLength = eric.length() - 1;
-
for( int n=0; n < strLength; n++){
-
if( eric.substr(n, 1) == " ")
-
{
-
eric.erase(n, 1);
-
-
}
-
-
-
}
-
return eric;
-
}
-
-
string tolower(string a)
-
{
-
int two;
-
int first = a.size();
-
for ( int two = 0; two < first; ++two)
-
{ a[two] = tolower(a[two]); }
-
return a;
-
}
-
int main(int argc, char *a0rgv[])
-
{
-
begining:
-
string whichone;
-
cout << "Encode or Decode? ";
-
cin >> whichone;
-
whichone = tolower(whichone);
-
if (whichone != "encode" && whichone != "decode" )
-
{
-
cout << "try again" << endl;
-
goto begining;
-
}
-
string keyword;
-
cout << "Keyword? ";
-
getline (cin, keyword);
-
keyword = tolower(keyword);
-
int keysize = keyword.size();
-
string keyletters[keysize];
-
int keyplc[keysize];
-
int x = 0;
-
int y = 0;
-
int k = 0;
-
string alph;
-
string compare;
-
alph = "abcdefghijklmnopqrstuvwxyz";
-
while (k <= keysize - 1)
-
{
-
keyletters[k] = keyword.substr(k,1);
-
int tester = -1;
-
tester = compare.find(keyletters[k]);
-
if(tester == -1)
-
{
-
keyplc[k] = alph.find(keyletters[k]);
-
alph.erase(keyplc[k],1);
-
compare = compare + keyletters[k];
-
}
-
k++;
-
}
-
string cypher;
-
cypher = compare + alph;
-
/*
-
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-
divider between first part and 2nd
-
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-
*/
-
if (whichone == "encode")// if Encode
-
{//starts if statment
-
string input;
-
cout << "Phrase? " ;
-
getline (cin, input);
-
input = removeAllWhite(input);
-
int strsize = input.size(); // finds the size of the string
-
string letters[strsize]; // array that holds the letters of the string
-
int numbers[strsize];
-
string yorn;
-
herea:
-
cout << "output encoded text to .txt file? Y/N: ";
-
cin >> yorn;
-
yorn = tolower(yorn);
-
if (yorn != "y" && yorn != "n")
-
{
-
cout << "try again" << endl;
-
goto herea;
-
}
-
if (yorn == "y")
-
{//begins output to text if statement
-
ofstream outputfile;
-
outputfile.open("output.txt",ios::out);
-
outputfile.close();
-
}//ends output to text if statement
-
while (x <= strsize - 1)
-
{//begins first while loop
-
letters[x] = input.substr(x,1);
-
while ( cypher.substr(y,1) != letters[x])
-
{//begins nested while loop
-
y++;
-
}//ends nested while loop
-
numbers[x] = y +1;
-
-
if (yorn == "y")
-
{//begins output to text if statement
-
ofstream outputfile;
-
outputfile.open ("output.txt",ios::app );
-
outputfile << numbers[x] << " ";
-
outputfile.close();
-
}//ends output to text if statement
-
cout << numbers[x]<< " " ;
-
y = 0;
-
x++;
-
}//ends while loop
-
if (yorn == "y")
-
{//begins output to text if statement
-
ofstream outputfile;
-
outputfile.open ("output.txt",ios::app);
-
outputfile << "END" << endl;
-
}//ends output to text if statement
-
cout << "END" << endl;
-
} // ends if statement
-
/*
-
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-
divider between 2nd part and third
-
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-
*/
-
if (whichone == "decode")
-
{//begins decode1 if statement
-
int digits;
-
cout << "number of digts to be decoded? ";
-
cin >> digits;
-
string decoded[digits];
-
int inputs[digits];
-
string yorn;
-
hereb:
-
cout << "Read digits to be decoded from .txt file? Y/N: ";
-
cin >> yorn;
-
yorn = tolower(yorn);
-
-
if (yorn != "y" && yorn != "n")
-
{
-
cout << "try again" << endl;
-
goto hereb;
-
}
-
if (yorn == "y")
-
{//begins yes if statement
-
string a;
-
hered:
-
cout <<"Is the .txt file in the same directory as the program? Y/N: ";
-
cin >> a;
-
a = tolower(a);
-
if (a != "y" && a != "n")
-
{
-
cout << "try again" << endl;
-
goto hered;
-
}
-
if (a == "y")
-
{
-
ifstream outputfile("output.txt");
-
int f = 0;
-
while (f < digits)
-
{
-
outputfile >> inputs[f];
-
f++;
-
}
-
}
-
if (a =="n")
-
{
-
char path [256];
-
cout << "Please enter the path for the desired file: ";
-
-
//cin >> path;
-
cin.getline (path,256);
-
cout << path << endl;
-
system("pause");
-
ifstream outputfile(path);
-
-
int f = 0;
-
while (f < digits)
-
{
-
outputfile >> inputs[f];
-
f++;
-
}
-
}
-
}//ends yes if statement
-
if (yorn =="n")
-
{//begins no if statement
-
-
cout << "Enter digts seperated by spaces: ";
-
int f = 0;
-
while (f < digits)
-
{
-
cin >> inputs[f];
-
f++;
-
}
-
}//ends no ifstatement
-
-
int f = 0;
-
while (f < digits)
-
{//begins decode2 if statement
-
decoded[f] = cypher.substr(inputs[f]-1,1);
-
cout << decoded[f] ;
-
f++;
-
}//ends decode2 if statement
-
cout <<endl;
-
}//ends decode1 if statement
-
string yesno;
-
herec:
-
cout << "run again? Y/N: ";
-
cin >> yesno;
-
//yesno = tolower(yesno);
-
if (yesno != "y" && yesno != "n")
-
{
-
cout << "try again" << endl;
-
goto herec;
-
}
-
if (yesno == "y")
-
{
-
goto begining;
-
}
-
if (yesno == "n")
-
{//begins don't run again if statment
-
-
return EXIT_SUCCESS;
-
}//ends don't run again if statement
-
}
-
5 3599
They work for me using Visual Studio.NET 2008.
What do you mean by "they don't worrk"?
donbock 2,426
Recognized Expert Top Contributor
I don't know if it is any prettier, but you could replace your goto's with do...while: - int firstLoop = 1;
-
do {
-
if (!firstLoop) {
-
<print error message>;
-
}
-
<do your thing>;
-
firstLoop = 0;
-
} while (<condition>);
what happens is there isn't a chance for me to input the text. So I guess you could say it skips the line.
donbock 2,426
Recognized Expert Top Contributor @erictheone
Do you see the "Keyword?" or "Phrase?" prompts?
I trust you would have told us if you keep getting "try again" messages.
Umm ... any chance of confusion between your tolower function for strings and the ctype tolower function that you're using on line 27? I don't know about C++, but it is not uncommon for tolower to be implemented as a macro in C.
Are you sure your input stream is not in a fail state?
Should cin encounter bad information, like trying to put a character into an int variable, it sets the fail state for the stream. Every subsequent cin first checks the fail state, and if set, does nothing but just returns. The effect os after the first cin sets the fail state all of the other cin statements appear to not exist.
I don't see any checks after any of your statements that use cin.
Like, if (cin.fail() etc...
Sign in to post your reply or Sign up for a free account.
Similar topics
by: NotGiven |
last post by:
|
by: Mark |
last post by:
Hi - could anyone please tell me why this line:
<td width="116" height="22" nowrap id="toptSearch" class="mtTabOnTop"
onClick="changeLoc('fixit_proceduresresultstick.asp','search')">Search
<img...
|
by: Field |
last post by:
Hi,
the following snippet shows once executed this output:
2
2
I'd have rather expected this output:
2
10
|
by: Claire |
last post by:
Is there an easy way to calculate the number of bytes that a UTF8 encoded
string will occupy within a file in advance of writing?
I am writing records to a complex file. These records contain...
|
by: Lal - Luxor |
last post by:
please help me.
how to work object.move will work on ve.net
regards
lal
|
by: Money |
last post by:
When we do this
Test *ptr=new Test;
then runtime memory manager will allocate 10*sizeof(Test) + X bytes(X
varying from implementation to implementation)
But instead if I call operator new...
|
by: alice |
last post by:
I'm trying to get sounds to play on image mouseovers using dreamweaver
8, and I found out that the code it generates to do this only works
for IE. Is there a way to do this so that it will work...
|
by: Damfino |
last post by:
Hi all,
Newbie question here wrt defining a class that will work on bits read
from a binary file. How would you go about doing it? As an example
please look at the structure of my data given...
|
by: Bergamot |
last post by:
marss wrote:
You may be trying to fix the wrong problem. Post a URL, then maybe we'll
see a better way to accomplish whatever your goal is.
--
Berg
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |