Advertisement
Guest User

Untitled

a guest
Aug 1st, 2015
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.26 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <math.h>
  4.  
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9. double num1; //An integer that the user will enter
  10. double num2;
  11. int numForRadian = 180;
  12. double pi, radius, area, circum, diam; //declaring the numbers the user will enter for the radius, area, etc.
  13. pi = 3.141592653589793238462643383279502884197169399375; //defining PI
  14. string userInput; //A variable needed for input into the program
  15. float base, power, total; //declaring the numbers need for indexing
  16. float radian;
  17. int angle;
  18. double percentage;
  19. char mathOp; //char variable for math operators i.e "+", "*" etc
  20. float sum; //float variable for the total of the two numbers the user enters
  21.  
  22.  
  23. do{ //Do while loop to loop through the program
  24. cout << "Please choose a Calculation you want to do: \nAddition - 1 \nMultiplication - 2 \nSubtraction - 3 \nDivison - 4 \nPower - 5 \nSquare Root - 6 " << endl;
  25. cout << "Cirlce Calculations - 7 \nDegree to Radian - 8 \nPercentage - 9" << endl;
  26. cin >> userInput;
  27.  
  28.  
  29. if(userInput == "1") //if statement for addition if user enters 1
  30. {
  31. cout << "You chose Addition!" << endl;
  32. cout << "Enter your calculation: " << endl;
  33. cin >> num1; //inputting integer
  34. cin >> mathOp;//inputting operator
  35. cin >> num2;
  36.  
  37. switch(mathOp)
  38. {
  39. case '+' : sum = num1 + num2; //if user enters 4+3 it will add
  40. break;
  41. }
  42.  
  43. cout << "= " << sum; //printing out the total of the numbers entered
  44.  
  45. }else if(userInput == "2")//same as last one just multiplies
  46. {
  47. cout << "\t* - Multiply" << endl;
  48. cout << "You chose Multiplication!" << endl;
  49. cout << "Enter your calculation: " << endl;
  50. cin >> num1;
  51. cin >> mathOp;
  52. cin >> num2;
  53.  
  54. switch(mathOp)
  55. {
  56. case '*' : sum = num1 * num2;
  57. break;
  58. }
  59.  
  60. cout << "= " << sum;
  61. }else if(userInput == "3")//subtract calculation
  62. {
  63. cout << "You chose Subtraction!" << endl;
  64. cout << "Enter your calculation: " << endl;
  65. cin >> num1;
  66. cin >> mathOp;
  67. cin >> num2;
  68.  
  69. switch(mathOp)
  70. {
  71. case '-' : sum = num1 - num2;
  72. break;
  73. }
  74.  
  75. cout << "= " << sum;
  76. }else if(userInput == "4")//division calculation
  77. {
  78. cout << "\t/ - Division" << endl;
  79. cout << "You chose Division!" << endl;
  80. cout << "Enter your calculation: " << endl;
  81. cin >> num1;
  82. cin >> mathOp;
  83. cin >> num2;
  84.  
  85. switch(mathOp)
  86. {
  87. case '/' : sum = num1 / num2;
  88. break;
  89. }
  90.  
  91. cout << "= " << sum;
  92.  
  93.  
  94. }else if(userInput == "5")//power calculation
  95. {
  96. cout << "You chose to Index your number!" << endl;
  97. cout << "Please enter your base number: ";
  98. cin >> base; //inputting the base number to index
  99.  
  100. cout << "Please enter the power: ";
  101. cin >> power; //inputting the power
  102.  
  103. total = pow(base, power); //calcualte the base and power e.g 5^3
  104.  
  105. cout << base << " to the power of " << power << " = " << total << endl; //prints out the total
  106.  
  107.  
  108. }
  109. else if(userInput == "6")///sqaure root calculation
  110. {
  111. cout << "You chose Square root!" << endl;
  112. cout << "Please enter the number you want to Sqaure Root: ";
  113. cin >> num1; //entering a number to sqrt
  114.  
  115. cout << "The sqaure root of " << num1 << " = " << sqrt(num1) << endl; //simple code to sqaure root the number
  116.  
  117. }else if(userInput == "7")//cirlce calculation
  118. {
  119. cout << "You chose Cirlce Calculations!" << endl;
  120. cout << "\nWhat do you want to calcualte?" << endl;
  121. cout << "Area - 1" << endl;
  122. cout << "Circumfrence - 2" << endl;
  123. cin >> userInput;
  124.  
  125. if(userInput == "1")//if user enters 1 it will go to the area calculation
  126. {
  127. cout << "Please input value of radius for the area: " << endl;
  128. cin >> radius;//inputting radius
  129. area = pi * (radius*radius); //calculating area e.g Pi*r^2
  130. cout << "The area of the cirlce is " << area << endl;//outputting area
  131. }
  132. else if(userInput == "2")//if user enters 2 it will calcualte circumfrence
  133. {
  134. cout << "Please input the diameter of the cirlce for the circumfrence: " << endl;
  135. cin >> diam;//inputting diameter
  136. circum = pi * diam;//calculating circumfrence e.g Pi*d
  137. cout << "The circumfrence is " << circum;//outputting cirumfrence
  138. }
  139. }else if(userInput == "8")
  140. {
  141. cout << "You chose to convert degrees to radians!" << endl;
  142. cout << "Enter your angle: " << endl;
  143. cin >> angle;
  144. radian = (pi / numForRadian) * angle;
  145.  
  146. cout << angle << " degrees in radian is " << radian;
  147.  
  148. }
  149. else if (userInput == "9")
  150. {
  151. cout << "You chose Percentage!" << endl;
  152. cout << "Enter your calculation: " << endl;
  153. cin >> num1;
  154. cin >> mathOp;
  155. cin >> num2;
  156. switch(mathOp)
  157. {
  158. case '/' : percentage = num1 / num2 * 100;
  159. break;
  160. default:
  161. cout << "Error - Invalid Input!";
  162. }
  163.  
  164. cout << "= " << percentage << endl;
  165.  
  166. }
  167.  
  168. cout << "\nWould you like to do another operation? (y/n)" << endl;
  169. cin >> userInput;
  170.  
  171. }while(userInput == "y");//if user enters "y" it will loop the program again
  172.  
  173. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement