- Joined
- Oct 1, 2004
- Location
- douglasville ga
Ok, so Im writing this program that will decrypt files. I just want to get the loops and such working first.
The problem is is that no matter the text file you put into the prompt, it starts. It overall is a big do while loop. Ive modeled it right after the examples in my book. If you can spot my mistake, please give me a hint. Im out of ideas.
Right now I have working:
It only accepts decryption codes 0-26 like its supposed to and memorizes them despite not putting in 0-26.
It has an input for the file name, but does not check to see if it is a valid file. The do while which 98% of the program is enclosed in should check the file using the ifstream inputfile;
Again, thank you for any help.
The problem is is that no matter the text file you put into the prompt, it starts. It overall is a big do while loop. Ive modeled it right after the examples in my book. If you can spot my mistake, please give me a hint. Im out of ideas.
Right now I have working:
It only accepts decryption codes 0-26 like its supposed to and memorizes them despite not putting in 0-26.
It has an input for the file name, but does not check to see if it is a valid file. The do while which 98% of the program is enclosed in should check the file using the ifstream inputfile;
Again, thank you for any help.
Code:
#include <iostream> // include iostream standard
#include <iomanip> // include io manipulation
#include <fstream> // include file stream
#include <cmath> // include cmath libraries
#include <cctype> // include cctypes.
using namespace std; // standard namespace
// end header
// start main function
int main ()
{ // declaration for char length,
const int length = 26;
// length of allowed files using const of 26 characters.
char readfile[length];
// Begin Printing Main Menu.
cout << "================================================" << endl;
cout << "Welcome to the Austin Powers Decryption Program!" << endl;
cout << "================================================" << endl;
// End Printing Main Menu
ifstream inputFile; // inputFile declared name for function to read .txt's
do
{
//Print prompt for file entry
cout << "Please type the name of the file to decrypt:";
cin >> readfile; // Entry for filename using variable readfile
inputFile.open(readfile); // open file entered for readfile
cout << "\n File loaded..." << endl << endl;
cout << "Please enter the three encryption codes." << endl << endl;
cout << "Enter integrals 0-26 for each code." << endl << endl;
//Variables Declared for the three entries.
int entry1; // First entry for cypher
int entry2; // Second entry for cypher
int entry3; // Third entry for cypher
// User input for encryption codes BEGIN
// Entry for first integer
cout << "\nEnter first integer here--->";
cin >> entry1;
//Check for valid first integer
while (entry1 < 0 || entry1 > 26)
{
cout << "\n ERROR: Invalid Number";
cout << "\n \n Please enter your first number again--->";
cin >> entry1;
}
// Entry for second integer
cout << "\nEnter the second integer here--->";
cin >> entry2;
// Check for valid second integer
while (entry2 < 0 || entry2 > 26)
{
cout << "\n ERROR: Invalid Number";
cout << "\n \n Please enter the second integer again--->";
cin >> entry2;
}
// Entry for third integer
cout << "\n Enter third integer here--->";
cin >> entry3;
// Check for valid third integer
while (entry3 < 0 || entry3 > 26)
{
cout << "\n ERROR: Invalid Number";
cout << "\n \n Please enter the third number again--->";
cin >> entry3;
}
// Display the integers picked
cout << "\n You have inputed the following codes:" << endl << endl;
cout << entry1 << endl << endl;
cout << entry2 << endl << endl;
cout << entry3 << endl << endl;
} while ( !inputFile ); //test for errors [invalid / non-existant file names]
return 0;
}