fork download
  1. //The program does simple calculations like add and sub
  2. #include <iostream>
  3. #include <cstdlib>
  4. using std::cout;
  5. using std::cin;
  6.  
  7. int dosum(int a,int b);
  8. int dosub(int a,int b);
  9.  
  10.  
  11. int main()
  12. {
  13. char ans;
  14. int a,b;
  15.  
  16. cout<<"What type of operation do wish to perform? enter a for additions or s for subtraction\n";
  17. cin>>ans;
  18. if(ans!='a'&& ans!='s')
  19. {
  20. cout<<"You entered the wrong answer for the opration to be performed\n";
  21.  
  22. exit(1); /*the program exits if the user enters a wrong specification for operation*/
  23. }
  24. cout<<"Input the two numbers\n";
  25. cin>>a, cin>>b;
  26.  
  27.  
  28. if (ans=='a'||ans=='A')
  29. {
  30. cout<<"The sum of the two numbers entered is "<<dosum(a,b)<<" \n";
  31. }
  32. else if(ans=='s'||ans=='S')
  33. {
  34. cout<<"The difference of the two numbers is "<<dosub(a,b)<<" \n";
  35. }
  36.  
  37. return 0;
  38. }
  39.  
  40. int dosum(int a,int b)
  41. {
  42. return a+b;
  43. }
  44.  
  45. int dosub(int a,int b)
  46. {
  47. return a-b;
  48. }
  49.  
Success #stdin #stdout 0s 16064KB
stdin
s
5
9
stdout
What type of operation do wish to perform? enter a for additions or s for subtraction
Input the two numbers
The difference of the two numbers is -4