Simple Calculator: Not Positive About Correct Usage of C++
Dear Fellow C++ Programmers,
I am currently just producing a simple scientific calculator to improve and refresh my memory on some skills (I'm a novice programmer). - I am not sure if what I wrote is legal, such as declaring a function from a class outside of the function (you will see). I tried to space out my coding nicely and added comments where my problems are. If anyone could provide aid I would very much appreciate it - thank you!
Code:
#include <iostream.h>
#include <stdlib.h>
int main() {
//global variables
char choice;
int ammount;
float a;
float b;
float c;
float answer;
//class containing functions to be created...
class op_function; {
op_add();
op_sub();
op_mul();
op_div();
op_sqr();
op_sqr_root();
op_pi();
op_sin();
op_cosin();
op_tan();
op_sci_notate();
op_retansw();
}
//main menu
cout << "Scientific Calculator Version 0.1 /n";
cout << "[01] Addition /n";
cout << "[02] Subtraction /n";
cout << "[03] Multiplcation /n";
cout << "[04] Division /n";
cout << "[05] Square /n";
cout << "[06] Square Root /n";
cout << "[07] Circle /n";
cout << "[08] Sin - Cosin - Tangent /n";
cout << "[09] Scientific Notation /n";
cout << "[10] Formulae /n";
cout << "[10] About Information /n";
cout << "Selection # ["
cin >> choice
cout << "] /n";
switch(choice) {
//case '01' is the selection for addition
//case '01' contains 1 overloaded function
case '01':
cout << "Addition Version 0.1 /n";
cout << "Supported: Three Floating Pnts. /n"
cout << "Specify Number Ammount: ";
cin >> ammount;
//does this first if statement go with the last else statement?
if (ammount == 1) {
cout << "Cannot Compute Value w/ One Number"; }
if (ammount == 2) {
cout << "Enter Num(1): ";
cin >> a;
cout << "/n";
cout << "Enter Num(2): ";
cin >> b;
//do I specify the decleration here? or in the class structure?
op_function.op_add(float a, float b);
op_function.op_add() {
return a + b; }
answer = op_function.op_add(a, b);
cout << "Answer: = " answer;
else {
cout << "Enter Num(1): ";
cin >> a;
cout << "/n";
cout << "Enter Num(2): ";
cin >> b;
cout << "/n";
cout << "Enter Num(3): ";
cin >> c;
//do I specify this here or in the class structure?
op_function.op_add(float a, float b, float c);
op_function.op_add() {
return a + b + c; }
answer = op_function.op_add(a, b, c);
cout << "Answer: = " answer; }
else {
cout << "Cannot Compute Value w/ One Number"; }
//Rest Is Unfinished
I am trying to maintain clean and professional looking code for my own reference and skill and in situations such as these. I hope it is clear enough to understand - if not, I guess i'll still be tinkering with it.