Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<math.h>
- using namespace std;
- int main()
- {
- int m1,m2,x,res,mlt,count;
- char yn;
- do
- {
- cout << "Welcome to The Multiplication Assistant";
- cout << "\n\nMultiplicand x Multiplier = Result";
- cout << "\n\nWhat is the 1st number (multiplicand)? ";
- cin >> m1;
- cout << "What is the 2nd number (multiplier)? ";
- cin >> m2;
- count = 0; //format spacing
- if(m1<0) count++;
- cout << "\nAdd "; //begin 1st line
- if (m2<0) {
- cout<<"-";
- count++; //output negative sign if negative
- }
- mlt = abs(m2); //absolute value in case of negative
- cout << m1 << " together " << mlt << " times "; //middle of 1st line
- res = m1 * m2; //math
- for(x=1;x<=mlt;x++)
- {
- if(m1<0) cout << "-"; //extra -
- cout << m1; // output multiplicantds between + signs
- if (x<mlt) cout << " + "; //+ signs end of 1st line
- }
- cout << " = " << res <<"\nResult ";
- for (x=1;x<=count;x++)
- cout << " "; //add format spaces
- printf(" %d X %d = %d",m1,m2,res); //2nd line
- cout << "\n\nWould you like to try another (Y/N)? "; //redo?
- cin >> yn;
- }while (yn!='N');
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement