3 Replies - 815 Views - Last Post: 17 February 2011 - 06:14 PM Rate Topic: -----

#1 Guest_la*


Reputation:

help with decryption program

Posted 17 February 2011 - 05:55 PM

I am trying to create a program that opens a file, asks the users for three integers and decodes the text. The integers must be between 0-26 corresponding to the letters in the alphabet. For example M+12=Y. I have most of the program I am just unsure how to write the decryption code. Can I write it using static_cast? Any help would be greatly appreciated!!

This is what I have so far:
#include <iostream>
#include <string>
#include <fstream>
using namespace std;

/*==================================================================================================== */

int main ()
{
	
	char fileName [24];
			
	
	cout << "===============================================" << endl;				//display title menu
	cout << "Welcome to the Austin Powers Decryption Program" << endl;
	cout << "===============================================" << endl << endl;

	ifstream inputFile;		
	
		cout << "Please enter the name of the file to decode: ";					//ask the user for fileName
		cin >> fileName;
		
		inputFile.open (fileName);													//open fileName
	
		while (inputFile == false)
	{
		inputFile.clear ();
		cout << fileName << " is not a valid file name. Please re-enter: ";
		cin >> fileName;
		inputFile.open (fileName);
	
			
		if (inputFile)
		{
			cout << "Next you will be prompted for the 3 decryption codes." << endl << endl;
			cout << "Please enter integers in the range 0 to 26 for each code." << endl << endl;
		}	
		}
		

	int integer1;																	// identify integers
	int integer2; 
	int integer3;
	
	cout << "Please enter the first integer: ";										// ask user for the first integer
	cin >> integer1;

	while (integer1 < 0 || integer1 > 26)											// check that integer is valid
	{
		cout << "Invalid. Please enter again: ";
		cin >> integer1;

	}

	cout << "Please enter the second integer: ";									// ask user for the second integer
	cin >> integer2;

	while (integer2 < 0 || integer2 >26)											// check that the integer in valid
	{
		cout << "Invalid. Please enter again: ";
		cin >> integer2;
	}

	cout << "Please enter the third integer: ";										// ask user for third integer
	cin >> integer3;

	while (integer3 < 0 || integer3 > 26)											// check that the integer is valid
	{
		cout << "Invalid. Please enter again: ";
		cin >> integer3;
	}

	
	
	inputFile.close ();

	return 0;
}


MOD EDIT: When posting code...USE CODE TAGS!!!

:code:

This post has been edited by JackOfAllTrades: 17 February 2011 - 06:01 PM


Is This A Good Question/Topic? 0

Replies To: help with decryption program

#2 ishkabible  Icon User is offline

  • spelling expret
  • member icon




Reputation: 1622
  • View blog
  • Posts: 5,709
  • Joined: 03-August 09

Re: help with decryption program

Posted 17 February 2011 - 06:04 PM

M+12=Y so M=Y-12, simple algebra us all it takes.
Was This Post Helpful? 0
  • +
  • -

#3 Guest_la*


Reputation:

Re: help with decryption program

Posted 17 February 2011 - 06:08 PM

View Postishkabible, on 17 February 2011 - 06:04 PM, said:

M+12=Y so M=Y-12, simple algebra us all it takes.


i just don't know how to write it in the program. i'm just stuck on how to write that using static_cast...
Was This Post Helpful? 0

#4 Guest_la*


Reputation:

Re: help with decryption program

Posted 17 February 2011 - 06:14 PM

View Postishkabible, on 17 February 2011 - 06:04 PM, said:

M+12=Y so M=Y-12, simple algebra us all it takes.


I'm not even sure if that makes sense, or if you can use static_cast..I just don't know how to put it in my program so that it decrypts the texts properly.

Thanks for your help!!
Was This Post Helpful? 0

Page 1 of 1