help i can not figure this out.

my home is to encryption a four digit number

I have to add 7 and use mod 10-- i think i have that part but now i need to swap the first number with the third and second with the fourth. i can not get it--here is my code

i know 41 is wrong but i am drawing a blank


//christine gershen
// Exercise 4.17: Encryption.cpp
// Encrypts data given by user.
#include <iostream> // required to perform C++ stream I/O
#include <iomanip> // required to perform setprecision stream manipulator

using namespace std; // for accessing C++ Standard Library members


int main() // function main begins program execution
{
int main=0;
int digit_one; //store digit one
int digit_two; //store digit two
int digit_three; //store digit three
int digit_four; //store digit four
int encryption; //store encryption

cout <<"Enter four-digit number:"; //asking the user to enter four-digit number

cin >> main; //four-digit number

digit_one=main/1000%10; // digit_one is first four-digit number

digit_two=main/100%10; // digit_two is second four-digit number

digit_three=main/10%10; //digit_three is third four-digit number

digit_four=main%10; //digit_four is fourth four-digit number

digit_one+=7%10; //add digit_two to 7 and mod 10

digit_two+=7%10; //add digit_two to 7 and mod 10

digit_three+=7%10; //add digit_three to 7 and mod 10

digit_four+=7%10); //add digit_four to 7 and mod 10

encryption=digit_three digit_four digit_one digit_two


cout <<"Encrypted digits:" << encryption <<endl; // display encrypted numbers


return 0; // indicate that program ended successfully

}// end function main


/**************************************************************************
* (C) Copyright 1992-2005 by Deitel & Associates, Inc. and *
* Pearson Education, Inc. All Rights Reserved. *
* DISCLAIMER: The authors and publisher of this book have used their *
* best efforts in preparing the book. These efforts include the *
* development, research, and testing of the theories and programs *
* to determine their effectiveness. The authors and publisher make *
* no warranty of any kind, expressed or implied, with regard to these *
* programs or to the documentation contained in these books. The authors *
* and publisher shall not be liable in any event for incidental or *
* consequential damages in connection with, or arising out of, the *
* furnishing, performance, or use of these programs. *
**************************************************************************/

Recommended Answers

All 9 Replies

Its just a matter of how you put them together, since they are separate variables you can just use third variable in the first of one and first in the place of third and same for the other two.

Its just a matter of how you put them together, since they are separate variables you can just use third variable in the first of one and first in the place of third and same for the other two.

that is what i thought but it is not working--

i rewrote the last line of code

digit_two+=7%10; //add digit_two to 7 and mod 10

digit_three+=7%10; //add digit_three to 7 and mod 10

digit_four+=7%10; //add digit_four to 7 and mod 10

cout <<"Encrypted digits:" << digit_three digit_four digit_one digit_ two <<endl; // display encrypted numbers

but now the confiler is give me this mess


1>f:\program class\tutorial 4\christine gershen tutorial 4\christine gershen tutorial 4\4.cpp(44) : error C2146: syntax error : missing ';' before identifier 'digit_four'
1>f:\program class\tutorial 4\christine gershen tutorial 4\christine gershen tutorial 4\4.cpp(44) : error C2146: syntax error : missing ';' before identifier 'digit_one'
1>f:\program class\tutorial 4\christine gershen tutorial 4\christine gershen tutorial 4\4.cpp(44) : error C2146: syntax error : missing ';' before identifier 'digit_'
1>f:\program class\tutorial 4\christine gershen tutorial 4\christine gershen tutorial 4\4.cpp(44) : error C2065: 'digit_' : undeclared identifier
1>f:\program class\tutorial 4\christine gershen tutorial 4\christine gershen tutorial 4\4.cpp(44) : error C2146: syntax error : missing ';' before identifier 'two'
1>f:\program class\tutorial 4\christine gershen tutorial 4\christine gershen tutorial 4\4.cpp(44) : error C2065: 'two' : undeclared identifier
1>f:\program class\tutorial 4\christine gershen tutorial 4\christine gershen tutorial 4\4.cpp(44) : error C2563: mismatch in formal parameter list
1>f:\program class\tutorial 4\christine gershen tutorial 4\christine gershen tutorial 4\4.cpp(44) : error C2568: '<<' : unable to resolve function overload
1> d:\program files\microsoft visual studio 9.0\vc\include\ostream(974): could be 'std::basic_ostream<_Elem,_Traits> &std::endl(std::basic_ostream<_Elem,_Traits> &)'
1> with
1> [
1> _Elem=wchar_t,
1> _Traits=std::char_traits<wchar_t>
1> ]
1> d:\program files\microsoft visual studio 9.0\vc\include\ostream(966): or 'std::basic_ostream<_Elem,_Traits> &std::endl(std::basic_ostream<_Elem,_Traits> &)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> d:\program files\microsoft visual studio 9.0\vc\include\ostream(940): or 'std::basic_ostream<_Elem,_Traits> &std::endl(std::basic_ostream<_Elem,_Traits> &)'

digit_four+=7%10);

remove )
you are not putting youre numbers properly

digit_four+=7%10);

remove )
you are not putting youre numbers properly

i am not sure what you mean?

this is my first class ---sorry

what order should they be?

i still need the fourth number to add 7 and %10

Once you separated the numbers why do you do add 7 to the number and mod by 10 ? Number is already encrypted. Now that you have each number encrypted and separated you should rearrange the order and multiply instead.

Another question I have is why are you modding constants? 7 % 10 is always going to be 7 so why not just put 7?

Once you separated the numbers why do you do add 7 to the number and mod by 10 ? Number is already encrypted. Now that you have each number encrypted and separated you should rearrange the order and multiply instead.

i got it figured out that's

i didn't have "<<" between my variables in the output list.

that is what i thought but it is not working--

i rewrote the last line of code

digit_two+=7%10; //add digit_two to 7 and mod 10

digit_three+=7%10; //add digit_three to 7 and mod 10

digit_four+=7%10; //add digit_four to 7 and mod 10

cout <<"Encrypted digits:" << digit_three digit_four digit_one digit_ two <<endl; // display encrypted numbers

but now the confiler is give me this mess


1>f:\program class\tutorial 4\christine gershen tutorial 4\christine gershen tutorial 4\4.cpp(44) : error C2146: syntax error : missing ';' before identifier 'digit_four'
1>f:\program class\tutorial 4\christine gershen tutorial 4\christine gershen tutorial 4\4.cpp(44) : error C2146: syntax error : missing ';' before identifier 'digit_one'
1>f:\program class\tutorial 4\christine gershen tutorial 4\christine gershen tutorial 4\4.cpp(44) : error C2146: syntax error : missing ';' before identifier 'digit_'
1>f:\program class\tutorial 4\christine gershen tutorial 4\christine gershen tutorial 4\4.cpp(44) : error C2065: 'digit_' : undeclared identifier
1>f:\program class\tutorial 4\christine gershen tutorial 4\christine gershen tutorial 4\4.cpp(44) : error C2146: syntax error : missing ';' before identifier 'two'
1>f:\program class\tutorial 4\christine gershen tutorial 4\christine gershen tutorial 4\4.cpp(44) : error C2065: 'two' : undeclared identifier
1>f:\program class\tutorial 4\christine gershen tutorial 4\christine gershen tutorial 4\4.cpp(44) : error C2563: mismatch in formal parameter list
1>f:\program class\tutorial 4\christine gershen tutorial 4\christine gershen tutorial 4\4.cpp(44) : error C2568: '<<' : unable to resolve function overload
1> d:\program files\microsoft visual studio 9.0\vc\include\ostream(974): could be 'std::basic_ostream<_Elem,_Traits> &std::endl(std::basic_ostream<_Elem,_Traits> &)'
1> with
1> [
1> _Elem=wchar_t,
1> _Traits=std::char_traits<wchar_t>
1> ]
1> d:\program files\microsoft visual studio 9.0\vc\include\ostream(966): or 'std::basic_ostream<_Elem,_Traits> &std::endl(std::basic_ostream<_Elem,_Traits> &)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> d:\program files\microsoft visual studio 9.0\vc\include\ostream(940): or 'std::basic_ostream<_Elem,_Traits> &std::endl(std::basic_ostream<_Elem,_Traits> &)'

You need to separate each variable you output with the operator "<<". Simply listing all the variables together appears nonsensical to the compiler. Well, more accurately, it appears nonsensical to the STL. Also, you have a space between "digit_" and "two" when declaring digit_two in your output, which makes them two separate variables, which I'm sure was not your intention.

That's hackish way of doing it.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.