C++ When the user enters the 4 digits, 1234 into this program, they get a result of 189, but the program requires 4 digits, how would you represent the 0 that is missing? Fix the program so that the output of the program should be 0189. #include using namespace std; int main() { int number; // The original number // Enter four-digit number to be encrypted cout << "Enter a four-digit number: "; cin >> number; // Encrypt (The digit numbers are counted from left) int digit1 = (number / 1000 + 7) % 10; int digit2 = (number % 1000 / 100 + 7) % 10; int digit3 = (number % 100 / 10 + 7) % 10; int digit4 = (number % 10 + 7) % 10; int encryptedNumber = digit1 * 10 + digit2 + digit3 * 1000 + digit4 * 100; cout << "Encrypted number is " << encryptedNumber << endl; // Enter an encrypted number to be decrypted cout << "Enter an encrypted number: "; cin >> number; // Decrypt (The digit numbers are counted from left) int digit5 = (number / 1000 + 3) % 10; int digit6 = (number % 1000 / 100 + 3) % 10; int digit7 = (number % 100 / 10 + 3) % 10; int digit8 = (number % 10 + 3) % 10; int decryptedNumber = digit5 * 10 + digit6 + digit7 * 1000 + digit8 * 100; cout << "Decrypted number is " << decryptedNumber << endl; } // End main
Max Function
Statistical function is of many categories. One of them is a MAX function. The MAX function returns the largest value from the list of arguments passed to it. MAX function always ignores the empty cells when performing the calculation.
Power Function
A power function is a type of single-term function. Its definition states that it is a variable containing a base value raised to a constant value acting as an exponent. This variable may also have a coefficient. For instance, the area of a circle can be given as:
C++
When the user enters the 4 digits, 1234 into this program, they get a result of 189, but the program requires 4 digits, how would you represent the 0 that is missing? Fix the program so that the output of the program should be 0189.
#include <iostream>
using namespace std;
int main()
{
int number; // The original number
// Enter four-digit number to be encrypted
cout << "Enter a four-digit number: ";
cin >> number;
// Encrypt (The digit numbers are counted from left)
int digit1 = (number / 1000 + 7) % 10;
int digit2 = (number % 1000 / 100 + 7) % 10;
int digit3 = (number % 100 / 10 + 7) % 10;
int digit4 = (number % 10 + 7) % 10;
int encryptedNumber =
digit1 * 10 + digit2 + digit3 * 1000 + digit4 * 100;
cout << "Encrypted number is " << encryptedNumber << endl;
// Enter an encrypted number to be decrypted
cout << "Enter an encrypted number: ";
cin >> number;
// Decrypt (The digit numbers are counted from left)
int digit5 = (number / 1000 + 3) % 10;
int digit6 = (number % 1000 / 100 + 3) % 10;
int digit7 = (number % 100 / 10 + 3) % 10;
int digit8 = (number % 10 + 3) % 10;
int decryptedNumber =
digit5 * 10 + digit6 + digit7 * 1000 + digit8 * 100;
cout << "Decrypted number is " << decryptedNumber << endl;
} // End main
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 1 images