### Simple Number Encryption [Error C2447 and IntelliSense]

Hi, I'm having some trouble with a program I'm trying to make for a uni assignment (first year so basic stuff).

The encrypting method used is that each digit in the given number is replaced by ((the sum of that digit plus seven) modulo 10) then the first and last “encrypted” digits are swapped.

I'm getting some errors though and I'd appreciate it if someone would be able to help me out, I've tried Googling and re-reading my code but can't seem to identify the problem.

I know that I'd be able to tidy this up using local variables rather than creating new ones during the process.

Current code;

 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778`` ``````/* 3-digit number encryption program */ #include using namespace std; int Digit1; int Digit2; int Digit3; int NewDigit1; int NewDigit2; int NewDigit3; int FinalDigit1; int FinalDigit2; int FinalDigit3; int originalNumber; int EncryptedNumber; int main() { cout << "Enter the original three-digit number:"; cin >> originalNumber; void isolateDigits(); void replaceDigits(); void swapDigit1WithDigit3(); void recomposeEncryptedNumber(); cout << "The Encrypted Number is:" ;EncryptedNumber; return 0; } { { /*find out the 3 digits that make up the number*/ void isolateDigits() Digit1 = (originalNumber / 100); Digit2 = ((originalNumber % 100) 10); Digit3 = (originalNumber % 10); } { { /*”encrypt” each of the three digits*/ void replaceDigits() NewDigit1 = ((Digit1 + 7) % 10); NewDigit2 = ((Digit1 + 7) % 10); NewDigit3 = ((Digit1 + 7) % 10); } } { { /*swap the first and last digit*/ void swapDigit1WithDigit3() FinalDigit1 = NewDigit3; FinalDigit2 = NewDigit2; FinalDigit3 = NewDigit1; } } { { /*recompose encrypted number from new values*/ void recomposeEncryptedNumber() EncryptedNumber = (((FinalDigit1 * 100) + (FinalDigit2 * 10) + (FinalDigit3)); } } }``````

Errors;
 ``123456789`` ``````1 - error C2447: '{' : missing function header (old-style formal list?) - line 32 2 - IntelliSense: expected a declaration - line 32 3 - IntelliSense: expected a '{' - line 38 4 - IntelliSense: expected a declaration - line 44 5 - IntelliSense: expected a '{' - line 50 6 - IntelliSense: expected a declaration - line 54 7 - IntelliSense: expected a '{' - line 61 8 - IntelliSense: expected a declaration - line 66 9 - IntelliSense: expected a "{" - line 73``````

Thanks in advance, you'd be doing me a massive favour helping me out here!
Last edited on
I don't usually bump topics on forums but this program has to be done by tomorrow morning 9am (currently 1:42am) and I hope to get a few hours sleep beforehand haha!

It's probably something obvious that should be staring me in the face but I am completely unaware of what's wrong with the above code...
Last edited on
You've misplaced a bunch of brackets.
Brackets come after the name of a function, and at the end of a function.

 ``12345678910111213`` ``````{ //<---- why is this here? { //<---- why is this here? /*find out the 3 digits that make up the number*/ void isolateDigits() // { <--- there should be a bracket here Digit1 = (originalNumber / 100); Digit2 = ((originalNumber % 100) 10); Digit3 = (originalNumber % 10); } { //<--- why is this here? ``````

Functions have the syntax of
 ``1234`` ``````type foobar() { //open bracket foo + bar //logic } //close bracket ``````

go back through your code and find where you left brackets out, and where you put brackets in for no reason.

Hope you get this thing working by the morning!
-Thumper
Last edited on
Thanks, much appreciated, that helped a lot!

It's now compiled with no errors, but whenever I try to use the program, all it will return is
"The encrypted number is: 0Press any key to continue . . ."

How do I fix this last (I hope!) issue?

Here's my amended code:
 ``1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768`` ``````/* 3-digit number encryption program */ #include using namespace std; int Digit1; int Digit2; int Digit3; int NewDigit1; int NewDigit2; int NewDigit3; int FinalDigit1; int FinalDigit2; int FinalDigit3; int originalNumber; int EncryptedNumber; int main() { cout << "Enter the original three-digit number:"; cin >> originalNumber; void isolateDigits(); void replaceDigits(); void swapDigit1WithDigit3(); void recomposeEncryptedNumber(); cout << "The encrypted number is: " << EncryptedNumber; return 0; } /*find out the 3 digits that make up the number*/ void isolateDigits() { Digit1 = (originalNumber / 100); Digit2 = ((originalNumber % 100) * 10); Digit3 = (originalNumber % 10); } /*”encrypt” each of the three digits*/ void replaceDigits() { NewDigit1 = ((Digit1 + 7) % 10); NewDigit2 = ((Digit1 + 7) % 10); NewDigit3 = ((Digit1 + 7) % 10); } /*swap the first and last digit*/ void swapDigit1WithDigit3() { FinalDigit1 = NewDigit3; FinalDigit2 = NewDigit2; FinalDigit3 = NewDigit1; } /*recompose encrypted number from new values*/ void recomposeEncryptedNumber() { EncryptedNumber = (((FinalDigit1 * 100) + (FinalDigit2 * 10) + (FinalDigit3))); }``````
Last edited on
in main, when you call a function you don't need to include it's type. The compiler thinks you're trying to declare a function in main.

 ``123456789101112`` ``````int main() { cout << "Enter the original three-digit number:"; cin >> originalNumber; // void isolateDigits(); // void replaceDigits(); //should be: isolateDigits(); replaceDigits(); //and so on. ``````
Just done that, but now I get this when trying to compile

This seems determined not to work haha! So near yet so far!
Last edited on
Woops, i missed that too.
The compiler reads your file linearly, so when there's no mention of isolateDigits before it's called, it doesn't know what you're referring to. So when you define functions underneath the main function, you need to prototype them

 ``123456789`` ``````void isolateDigits(); //these are prototypes. void replaceDigits(); void swapDigit1WithDigit3(); void recomposeEncryptedNumber(); int main() { //code }``````

When your compiler reaches the call of isolateDigits() in main, it realizes that it's been mentioned before, and knows what to look for.
It now works and encrypts numbers correctly! :D

Thanks so much!!!

Just one very final touch now is that I need leading zeroes on the output - i.e. the output "20" will be represented as "020". Any easy way to do this?
Before outputting EncyptedNumber, test to see if it's less than 100. If so, manually output a "0" before the number.
The same applies if it's less than 10, output two zeroes.

 ``123`` ``````//in main if(EncryptedNumber < 100 || EncryptedNumber >= 10) cout << "0" << EncryptedNumber << endl;``````

Simple, not very complex, but it should work.
*Deleted*
Last edited on
You are correct. My example would only work for one trailing zero.
I left the situation of two trailing zeroes out under the assumption you'd fill it in :P
The logic is the same. If < then 10, and > than 0, add two zeroes, then output EncryptedNumber.

I re-read your post again, and have now edited mine and feel like an idiot for even asking the question haha.

Been in the library for over six hours now doing various assignments and revising - time well spent but my cognitive functioning is now suffering haha!

Thanks again!
I thought I was done asking questions for the night but one last one;

How do I get those if statements to co-exist and ignore each other if necessary?

 ``1234567891011121314151617181920212223`` ``````int main() { cout << "Enter the original three-digit number:"; cin >> originalNumber; isolateDigits(); replaceDigits(); swapDigit1WithDigit3(); recomposeEncryptedNumber(); cout << "The encrypted number is "; if(EncryptedNumber < 100 || EncryptedNumber >= 10) cout << "0" << EncryptedNumber << endl; if(EncryptedNumber < 10 || EncryptedNumber >= 0) cout << "00" << EncryptedNumber << endl; cout << "\n"; return (0);``````

And my output from the program reads (user input is the 333 which when encrypted should result in 000)

 ``12345`` ``````Enter the original three-digit number:333 The encrypted number is 00 000 Press any key to continue . . . ``````

How can I get it to just display the "000"
The answer for such a simple problem must be staring me in the face but my lack of sleep is punishing me severely.

Edit - And for 073 I'm getting

 ``12`` ``````The encrypted number is: 047 0047``````
Last edited on
You need use AND comparison instead of OR. You want both conditions to be true in order to determine whether to put one or two zeroes up. (that was originally my bad. It's pretty late at night for me too, so i'm also having trouble thinking. Lol.)

 ``1234567`` ``````cout << "The encrypted number is "; if(EncryptedNumber < 100 && EncryptedNumber >= 10) cout << "0" << EncryptedNumber << endl; else if(EncryptedNumber < 10 && EncryptedNumber >= 0) cout << "00" << EncryptedNumber << endl; else cout << "Encrypted number > 999, or < 0. (out of bounds)" << endl;``````
Sorted.

Said it a few times already, but thanks! :D

Good night dude! :)
Anytime.
how do i fix the error with the open bracket above the line starting with char?

#include <iostream>

using namespace std;

void menu(int a, int b, int c, int d, char symbol);
float numerator,denominator;
void addFractions(int a,int b, int c, int d, int &numerator, int &denominator);
void subtractFractions(int a, int b, int c, int d, int &numerator, int &denominator);
void multiplyFractions (int a, int b, int c, int d, int &numerator, int &denominator);
void divideFractions (int a, int b, int c, int d, int &numerator, int &denominator);

int main()
{
int a, b, c, d;

cout << "first, we will need your numerators/denominators." << endl;
cout << "What is your first fractions numerator?" << endl;
cin>> a;
cout << "What is your first fractions denominator?" << endl;
cin >> b;
cout << "What is your second fractions numerator?" << endl;
cin >> c;
cout << "What is your second fractions denominator?" << endl;
cin >> d;
}

void menu(int a, int b, int c, int d, char symbol)
{

cout << "choose one of the following: + (addition), - " <<
"(subtraction), * (multiplication), and finally / (division)." << endl;
cin >> symbol;
cout << endl;
}

{

char '*';
multiplyFractions(a,b,c,d,numerator, denominator);
cout << "Answer is " << numerator << "/" << denominator << endl;

char '/':
divideFractions(a,b,c,d,numerator, denominator);
cout << "Answer is " << numerator << "/" << denominator << endl;

char '+':
addFractions(a, b, c, d, numerator, denominator);
cout << "Answer is " << numerator << "/" << denominator << endl;

char '-':
subtractFractions(a,b,c,d,numerator, denominator);
cout << "Answer is " << numerator << "/" << denominator << endl;

}

void addFractions (int a, int b, int c, int d, int &numerator, int &denominator)
{
numerator = (a*d) + (b*c);
denominator = (b*d);
}
void subtractFractions (int a, int b, int c, int d, int &numerator, int &denominator)
{
numerator = (a*d)-(b*c);
denominator = (b*d);
}
void multiplyFractions(int a, int b, int c, int d, int &numerator, int&denominator)
{
numerator = (a*c);
denominator = (b*d);
}
void divideFractions(int a, int b, int c, int d, int &numerator, int &denominator)
{
numerator = (a*d);
denominator = (b*c);
}
Topic archived. No new replies allowed.