Calculator

So i made this calculator program using some functions.
I'm still very new to C++, and programming in general, but i think the code shows some useful things.

Helpful criticism very welcome!

Thank you

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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#include <iostream>
#include <math.h>
#include<windows.h>

using namespace std;
//Function Prototypes
//Addition
void add (float number1, float number2)
{
  cout << "total - " << number1 + number2 << endl << endl;
}
//Subtraction
void subtract (float number1, float number2)
{
  cout << "total - " << number1 - number2 << endl << endl;
}
//Multiplication
void multiply (float number1, float number2)
{
  cout << "total - " << number1 * number2 << endl << endl;
}
//Division
void divide (float number1, float number2)
{
  cout << "total - " << number1 / number2 << endl << endl;
}
//Powers
void power (float number1, float number2)
{
  cout << "total - " << pow (number1, number2) <<endl << endl;
}
//Main Function
int main()
{
SetConsoleTitle("Advanced Calculator ++ by Noah Sharbonda");
//Create Variables
int menu;
float num1;
float num2;
//Menu
  cout << "Select Something to do!" << endl;
  cout << "(ADD: 1) (SUBTRACT: 2) (MULTIPLY: 3) (DIVIDE: 4)" << endl;
  cout << "(POWERS: 5) (SQUARE ROOT: 6) (FRACTIONS: 7) (SQUARE AND CUBE: 8)" << endl;
  cout << "(Exit: 9)" << endl;
  cin >> menu;
//Addition
  if (menu == 1)
  {
      cout << "Enter a number " << endl;
      cin >> num1;
      cout << "Enter the number you would like to add " << endl;
      cin >> num2;
      add (num1, num2);
  }
//Subtraction
  if (menu == 2)
    
  {
      cout << "Enter a number " << endl;
      cin >> num1;
      cout << "Enter the number you would like to subtract " << endl;
      cin >> num2;
      subtract (num1, num2);
  } 
  
  if (menu == 3)
//Multiplication
  {
      cout << "Enter a number " << endl;
      cin >> num1;
      cout << "Enter the number you would like to multiply " << endl;
      cin >> num2;
      multiply (num1, num2);
  }
//Division
  if (menu ==4)
  {
      cout << "Enter a number " << endl;
      cin >> num1;
      cout << "Enter the number you would like to divide " << endl;
      cin >> num2;
      divide (num1, num2);
  }
//Powers
  if (menu == 5)
  {
      cout << "Enter a number " << endl;
      cin >> num1;
      cout << "to the power of ";
      cin >> num2;
      power (num1, num2);
  }
//Square Root
  if (menu == 6)
  {
      cout << "Enter a number " << endl;
      cin >> num1;
      cout << "Square root - " << sqrt (num1) << endl << endl;
  }
//Fractions
  if (menu == 7)
  {
      cout << "Enter a number " << endl;
      cin >> num1;
      cout << "one half - " << num1/2 << endl;
      cout << "one 3rd - " << num1/3 << endl;
      cout << "one 4th - " << num1/4 << endl;
      cout << "one 5th - " << num1/5 << endl;
      cout << "one 6th - " << num1/6 << endl;
      cout << "one 7th - "<< num1/7 << endl;
      cout << "one 8th - " << num1/8 << endl;
      cout << "one 9th - "  << num1/9 << endl;
      cout << "one 10th - "  << num1/10 << endl;
      cout << "one 15th - " << num1/15 << endl;
      cout << "one 16th - " << num1/16 << endl;
      cout << "one 17th - " << num1/17 << endl;
      cout << "one 18th - " << num1/18 << endl;
      cout << "one 19th - " << num1/19 << endl;
      cout << "one 20th - " << num1/20 << endl;
      cout << "one 32nd - " << num1/32 << endl << endl;
  }
//Square and Cube
  if (menu == 8)
  {
      cout << "Enter a number " << endl;
      cin >> num1;
      cout << "Squared " << pow (num1, 2) << endl;
      cout << "Cubed " << pow (num1, 3) << endl << endl;
  }
  if (menu == 9)
  {
       return 0;
  }

  main();
  }
Topic archived. No new replies allowed.