Advertisement
Guest User

Untitled

a guest
Feb 28th, 2020
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.23 KB | None | 0 0
  1. #include<iostream>
  2. #include<math.h>
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7. int m1,m2,x,res,mlt,count;
  8. char yn;
  9.  
  10. do
  11. {
  12. cout << "Welcome to The Multiplication Assistant";
  13. cout << "\n\nMultiplicand x Multiplier = Result";
  14. cout << "\n\nWhat is the 1st number (multiplicand)? ";
  15. cin >> m1;
  16. cout << "What is the 2nd number (multiplier)? ";
  17. cin >> m2;
  18.  
  19. count = 0; //format spacing
  20. if(m1<0) count++;
  21.  
  22. cout << "\nAdd "; //begin 1st line
  23.  
  24. if (m2<0) {
  25. cout<<"-";
  26. count++; //output negative sign if negative
  27. }
  28. mlt = abs(m2); //absolute value in case of negative
  29.  
  30. cout << m1 << " together " << mlt << " times "; //middle of 1st line
  31.  
  32. res = m1 * m2; //math
  33.  
  34. for(x=1;x<=mlt;x++)
  35. {
  36.  
  37. if(m1<0) cout << "-"; //extra -
  38. cout << m1; // output multiplicantds between + signs
  39. if (x<mlt) cout << " + "; //+ signs end of 1st line
  40. }
  41.  
  42. cout << " = " << res <<"\nResult ";
  43.  
  44. for (x=1;x<=count;x++)
  45. cout << " "; //add format spaces
  46.  
  47. printf(" %d X %d = %d",m1,m2,res); //2nd line
  48.  
  49. cout << "\n\nWould you like to try another (Y/N)? "; //redo?
  50. cin >> yn;
  51.  
  52. }while (yn!='N');
  53. return 0;
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement