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;

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/* 3-digit number encryption program */
#include <iostream>
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;
1
2
3
4
5
6
7
8
9
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.

1
2
3
4
5
6
7
8
9
10
11
12
13
{ //<---- 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
1
2
3
4
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:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/* 3-digit number encryption program */
#include <iostream>
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.

1
2
3
4
5
6
7
8
9
10
11
12
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

"Error C3861: isolateDigits": Identifier not found"

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

1
2
3
4
5
6
7
8
9
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.

1
2
3
//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.

Glad i could help.
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?

My main now reads

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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)

1
2
3
4
5
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

1
2
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.)

1
2
3
4
5
6
7
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.
Take it easy man, glad I could help you out.
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.