Oct 6, 2014 at 8:58pm UTC
Hi everyone,
I am trying to write a code taht gets an alpahbet and return teh previous letter, except for Z or z that must return 9..
I dont know what I am doing wrong but I am not getting that outcomes at all
#include "stdafx.h"
#include <iostream>
using namespace std;
char encript(char &alph)
{
char result;
char alphabet[] =
"abcdefghijklmnopqrstuvwxyz"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ";
int alphabetlength = strlen(alphabet);
for (int j = 0; j<alphabetlength; j++)
{
if (alph = 'z')
{
result = '9';
}
else
{
if (alph == alphabet[j])
{
result = alphabet[j - 1];
}
}
}
return result;
}
bool checkit(char inChar)
{
if (inChar != '9') return true;
return false;
}
int main(int argc, char* argv[])
{
char c1 = 'I';
char c2 = 'B';
char c3 = 'M';
char aChar;
char var;
cout << "The characters " << c1 << c2 << c3 << " are ";
cout << encript(c1) << encript(c2) << encript(c3) << endl;
do{
cout << "Enter a character ";
cin >> aChar;
var = aChar;
cout << " achar encripted is " << encript(aChar);
cout << " achar was " << var << " now is " << aChar << endl;
} while (checkit(aChar));
return 0;
}
Last edited on Oct 6, 2014 at 9:56pm UTC