Can someone help me I keep getting an error code on this line and I cannot figure it out.

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

________________________________________________________________________________________

#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

// function main begins program execution
int main()
{  
    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

    cout <<"Enter four_digit number"; // asking the user to enter four_digit number
    cin >>main; // four_digit number

    digit_one=main%10; // digit_one is first four_digit number
    digit_two=main/10%10; // digit_two is second four_digit number
    digit_three=main/100%10; // digit_three is third four_digit number
    digit_four=main/1000%10; // digit_four is fourth four_digit number

    digit_one=(digit_one+7%10); // adds digit_one to 7 and mod 10
    digit_two=(digit_two+7%10); // adds digit_two to 7 and mod 10
    digit_three=(digit_three+7%10); // adds digit_three to 7 and mod 10
    digit_four=(digit_four+7%10); // adds digit_four to 7 and mod 10

    cout <<"Encrypted digits:"; << digit_three; digit_four; digit_one; digit_two; << 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.                     *
 **************************************************************************/

There's a semi-colon after your string. Remove it.

Also, separate your variables in output by << operators and not semi-colons.

/**************************************************************************
 * (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. *
 **************************************************************************/

Well, this is obviously taken from a text. What exactly is the purpose of the chapter and/or exercise this excerpt was taken from? I think I should be cautious about how I answer until I know.

To answer your question though, there is a syntax error on the line in question.

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

There's a semi-colon after your string. Remove it.

Also, separate your variables in output by << operators and not semi-colons.

True, the extraneous semi-colon is a syntax error, but there's more wrong with that line than just that. There are also other syntax errors and intent errors in the line.

This is a homework assaignment from Simply C++ Deitel book, I put the semi-colons back because when I took them out I still got an error. Can you show me what that code should look like, I am a beginner sorry don't understand.

Well, this is obviously taken from a text. What exactly is the purpose of the chapter and/or exercise this excerpt was taken from? I think I should be cautious about how I answer until I know.

To answer your question though, there is a syntax error on the line in question.

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

True, the extraneous semi-colon is a syntax error, but there's more wrong with that line than just that. There are also other syntax errors and intent errors in the line.

True. I noticed the same right after and made some quick changes. Thanks.

@Chilton;

I did what u said to do, but it still not printing the way that it is supposed to:

cout <<"Encrypted digit:" << "digit_three" <<"digit_four" <<"digit_one" <<" digit_two" << endl; // display encrypted numbers

digit_one to digit_four are variables. You don't need to put them in quotes to display them. Review variables and cout structure to get a better handling on these basics.

You're getting closer with this, but in this case, you do not want the double-quotes around the variable names; double quotes are used to demarcate the beginning and end of a string literal. Thus, you should try the following:

cout <<"Encrypted digit:" << digit_three << digit_four << digit_one << digit_two << endl; // display encrypted numbers

As a side note, I should mention that in the future you should always use [code] tags around any code samples you post here. This ensures that the source formatting is retained.

Getting back to the program: at the beginning of the program, you have a variable named main , which you declare as type int and assign the value of zero. I would expect this to conflict with the function name main() , or else get treated as an overload of that name. Either way, having a variable with the same name as a function is almost certain to result in confusion, if not on the part of the compiler then on the part of those reading the code later. I strongly recommend renaming the variable to something other than main .

ok I changed it, but it is still not printing what I need it to print. like this:

Enter four-digit number: 1234

Encrypted digits: 0 1 8 9

press any key to continue_

It should print this

I suspect that the output you are getting is more like this:

Enter four-digit number:1234

Encrypted digits:0189

press any key to continue_

This is a simple matter of adding (space) characters to your output formatting. This code:

#include <iostream>

using std::cout;
using std::cin;

int main () {
  int theNumber = 10;
  cout << "The number is" << theNumber << "please take note.";
  cin.get();
  return 0;
}

is not the same as this code:

#include <iostream>

using std::cout;
using std::cin;

int main () {
  int theNumber = 10;
  cout << "The number is " << theNumber << " please take note.";
  cin.get();
  return 0;
}

Notice the subtle differences in the output statements (the spaces I added to the strings around the number). You need to make sure you tell the program everything that you want it to output. It can't magically assume that something should or shouldn't be there. If you don't tell it to output a ' ' (space), it won't.

This is what I have so far. But it is not printing the way that it is supposed to like in your quote.

#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

// function main begins program execution
int main()
{  
    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

    cout <<"Enter four_digit number"; // asking the user to enter four_digit number
    cin >>main; // four_digit number

    digit_one=main%10; // digit_one is first four_digit number
    digit_two=main/10%10; // digit_two is second four_digit number
    digit_three=main/100%10; // digit_three is third four_digit number
    digit_four=main/1000%10; // digit_four is fourth four_digit number

    digit_one=(digit_one+7%10); // adds digit_one to 7 and mod 10
    digit_two=(digit_two+7%10); // adds digit_two to 7 and mod 10
    digit_three=(digit_three+7%10); // adds digit_three to 7 and mod 10
    digit_four=(digit_four+7%10); // adds digit_four to 7 and mod 10

    cout <<"Encrypted digit:" << digit_three << digit_four << digit_one << digit_two << endl; // display encrypted numbers

    return 0; // indicate that program ended successfully

} // end function main

You're not listening. Tell us what the output you are receiving is and how it differs from the output expected.

Unless you give us the appropriate information, we can't provide any useful help. Help us help you.

This is what it's supposed to print

Enter four-digit number: 1234

Encrypted digits: 0 1 8 9

press any key to continue_

This is what it's printing

Enter four-digit number: 1234

Encrypted digits: 981110

press any key to continue_

OK, now we're getting somewhere.

First thing's first. Your digit isolation code is backward:

digit_one=main%10; // digit_one is first four_digit number
 digit_two=main/10%10; // digit_two is second four_digit number
 digit_three=main/100%10; // digit_three is third four_digit number
 digit_four=main/1000%10; // digit_four is fourth four_digit number

This code collects the digits from right-to-left instead of left-to right. This line:

digit_one=main%10; // digit_one is first four_digit number

is working with the '4', not the '1' as you seem to assume. You'll have to flip this whole section over.

Next, this section:

digit_one=(digit_one+7%10); // adds digit_one to 7 and mod 10
 digit_two=(digit_two+7%10); // adds digit_two to 7 and mod 10
 digit_three=(digit_three+7%10); // adds digit_three to 7 and mod 10
 digit_four=(digit_four+7%10); // adds digit_four to 7 and mod 10

Order of operations is biting you here. Modulo is a division operation. Multiplication and division are handled before addition and/or subtraction. The net result of all these equations is [I]digit[/I]+7 . This is why you are getting a 10 and an 11 instead of a 0 and a 1.

And this section:

cout <<"Encrypted digit:" << digit_three << digit_four << digit_one << digit_two << endl; // display encrypted numbers

Is there a particular reason you are placing digit_three and digit_four in front of digit_one and digit_two? You will need to re-arrange this section, and add the appropriate white-space between the digits.

This application must do the filing but I am having a compiler error; Can someone please help me.

( Password Generator Application) Write an application that generates a password from a five- character string that the user enters. The application should generate the password by reversing the order of the string and subtracting 15 from each characters ASCII code. If the user enters a string that does not contain exactly five characters, the application should display an error message and exit.

1. Including the <string> standard library header file. In line 5, insert a preprocessor directive to include the <string> standard library header file so that you can access the string class.

2. Defining variables to store user input. In lines 12-14, insert a full- line comment and define string variable plainText to store user input, and char variable password, to contain a password character.

3. Prompting the user for a five- character string. In lines 16-18, prompt the user for a five-character string.

4. Generating a password. In lines 21-24, include the if part of an if... else statement. The if part should determine whether the string has five characters. If not, the body of the if statement should display an error message. The else part of the if... else statement should generate a password. First, display descriptive text for the password. To generate the password, you must modify each character of user input individually. To access each character of the string plainText, you will use string function at. When you call the at function, you must specify the position of the character that you want to access. The first character in a string is located at position 0, the second at position 1, the third and position 2 and so on. For example, the expression plainText. at(1) returns the second character in the string. For each character in plainText, subtract 15 from the current character and assign the result to password. Use cout to display the value contained in password. Recall that C++ allows such manipulations of chars because they are stored as integers. Start with the last plain text character, which can be accessed by calling plainText. at(4). For each character in plainText, modify the integer value of the character, assign the result to password and display it. After displaying the last password character, insert two endl stream manipulators in cout.


// This application inputs a five-character string and generates
// a password from it.
#include <iostream> // required to perform C++ stream I/O
#include <string> // required to access string functions

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

// function main begins program execution
int main()
{
// define variables
string plainText; // stores user input
char password; // contain password character

// prompt user for five character string
cout << "\nEnter five-character string: ";
getline( cin, plainText );

// display error message if five characters are not entered
if ( plainText.size() < 5 )
{
// display error message
cout << "\nError: You must enter a name\n" << endl;
} // end if
else // otherwise, do calculations to get password
{
// display password
cout << "\nPassword is: " << plainText.at( 4 ) - 15 << plainText.at( 3 ) - 15
<< plainText.at( 2 ) - 15 << plainText.at( 1 ) - 15
<< plainText.at( 0 ) - 15 << endl << endl;
cin >> password; // stores the character to password

} // end if


return 0; // indicate that program ended successfully

} // end function main

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.