I figured instead of registering on another forum, I'd come here and maybe someone can answer my basic question. Right now I am testing my development skills and trying a simple exercise. I am trying to produce a program that will take a user inputed string and convert each individual character to the numeric value of the alphabet (e.g. A=/1/, Z=/26/)
This is nothing more then a basic string crypter and soon I will program a decrypter. I have got a little bit of it through previous knowledge and looking up some stuff but now I am stuck as to what to do. Here is what I have so far:
Code:
#include <iostream>
#include <string>
using namespace std;
int main () {
string uncrypt;
int num;
int c;
cout << "Please enter your word to be crypted: ";
cin >> uncrypt;
num = uncrypt.length();
for(c = 0; (c = num); c++)
{
//Stuff Here
}
}
Hey Cttyssha and welcome to Geeks to Go,
I have not compiled your code or anything but have spotted an issue in your loop control statement...
A for loop is in the format:
for( [loop variable initialization and start value], [execution condition], [increment variable] )
The problem existing in your [execution condition] where by the value requires being true in order to execute the code in the loop statement. When this value gets set to false at some point the loop will stop and not execute longer and your program will continue as normal executing anything after the loop.
The first issue is that you are not using a comparison operator == and instead using the assignment operator =. I stand corrected, but your compiler should complain about this statement as the second parameter expected a boolean type value...
The second issue is that even if you did use a comparison operator ==, your condition reads: (c == num) where on the first loop where c = 0, num will hold the length on the string captured by the input stream; this means unless the string length is equal to 0 your loop [execution condition] will result in a false value.
Usually a template for "for loops" [execution condition] in the form you have it is as follows:
for(c = 0; c < num; c++)
So to elaborate on the condition where c < num, will always execute as true as long as "num" is less than "c"; therefor your loop should execute "num" times until the condition becomes false as "c" gets incremented.
I hope this somewhat assists you... Please let me know if you need any other explanation or assistance.
Peace Out
Spike