Alright so first I'll ask my question and than post what my professor wants. First I'm trying to line the numbers up on the right side just like he does in the examples. Next I have to show of the each steps, and I'm not exactly sure how to do that or if I'm missing something :) Havent coded in a while. Also, if I'm missin anythin else please let me know! Thank you in advance!! Also I'm not exactly done with everythin in the code so I'll post updates.
Now here is what my professor says : In traditional "long multiplication" we determine the product of two integers, x and y, by
multiplying x and the individual digits of y, in turn, starting with the unit’s digit. The results of these
multiplications are arranged appropriately and added, yielding the completed product. The
representation of these operations are usually done in a particular manner. For example, the
multiplication of 123 by 95 is:
123
95
x ---
615
1107
-----
11685
The numbers to be multiplied, x and y, are each displayed on a separate line, followed by a horizontal
line. The results of multiplying each digit of y by x are then displayed on separate lines, followed by
another horizontal line, and then the final product. Write a C++ program to perform a sequence of
such multiplications, displaying the results in this traditional representation. Input will be two
integers, x and y from the keyboard. Each integer will have no more than 10 digits.
For each pair of integers, perform the multiplication of x by y, displaying the results similar to
example shown above. If y contains only a single significant digit, omit the second horizontal line and
the sum (since it would be overkill). Display 0 digits only when they are significant. The number of
hyphens (-) in the first horizontal line should be the same as the number of digits in the larger value of
x and y. The number of hyphens in the second horizontal line, if it is produced, should be the same as
the number of digits in the product of x and y. Output the letter x for the multiplication symbol in the
answer. Check only for positive numbers (including 0). Finally, ask the user if he/she wishes to run the
program again. No credit will be given for just giving the answer without showing the steps involved.
Output should look similar to below.
Sample Runs:
Enter the first number: 4
Enter the second number: 7
4
7
x --
28
Run again (Y/N)? y
Enter the first number: 135
Enter the second number: 46
5
135
46
x ---
810
540
----
6210
Run again (Y/N)? N
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
|
#include <iostream>
using namespace std;
int main()
{
int X; //Variable for the first number
int Y; // Variable for the second number
char Answer; //Variable for the run again
cout << "Please enter the First number :";
cin >> X;
cout << "Please enter the Second number : ";
cin >> Y;
int Total = X * Y; // To get the multiplication total
cin.get();
cout << X << endl; //Displays the first number
cout << Y << endl; //Displays the Second number
cout << "x----" << endl;
cout << Total << endl;
cout << "Run Again? (Y/N) :";
cin >> Answer;
}
|