Homework- Include Arithmetic and Trignometric Functions in a calculator- Please help!

Hello,

I'm a beginner in an entry level C++ class. Currently, I have an assignment due tomorrow in which I must write code to use function, and switch statements in a C++ program which can perform arithmetic and trignometric functions depending on the user's input..below I displayed the actual text of the assignment

"In this project, you will program a simple calculator which does basic arithmetic, trigonometric and operations. In this program, you will exercise “function”, “switch” statements in C++ program. (Your program should contain “switch” statement which accepts user input for either “arithmetic” or “trigonometric” calculations.)
Once user input is selected, proper function is called. For example, “arith( )” for arithmetic calculations and “trigono( )” for “trigonometric ones.
Once those functions are called, user is asked to enter his/her desired computation through another case statement. Based on user input, your calculator performs proper computation after accepting user input numbers. The output from computation should be displayed to your monitor.

My actual code that I have done so far is below, I know it is the arithmetic portion...can someone please help me correct any errors I have created and someone help me include trigonometric functions. I'm lost how to include trigonometric functions if someone can help me please :(

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
  //Project Homework #3
#include <math.h>
#include <iostream>
using namespace std;

int main () {

	cout <<"Welcome to Robert's calculator." <<endl;
	int 1,2; //declaring variables
	int result;  //look for result
	int arith(), int trigono()
	cout <<"Press 1 for Arithmetic and 2 for Trignometric Calculation: ";  //states to user press 1 to use arithmetic calculator and 2 for Trignometric Calculator
	cin  >> 1;  
	cin  >> 2;
}

int main()
{
	double Operand1, Operand2, Result;
	char Operator;

	cout << "This program allows you to perform an operation on two numbers\n";
	cout << "To proceed, enter a number, an operator, and a number:\n";
	cin >> Operand1 >> Operator >> Operand2;

	switch(Operator)
	{
	case '+':
		Result = Operand1 + Operand2;
		break;

	case '-':
		Result = Operand1 - Operand2;
		break;

	case '*':
		Result = Operand1 * Operand2;
		break;

	case '/':
		Result = Operand1 / Operand2;
		break;
		
	}

	cout << "\n" << Operand1 << " " << Operator << " "
		 << Operand2 << " = " << Result;

	cout << "\n\n";
For starters, prefer <cmath> to <math.h>. You have to main functions, I presume the bottom one was meant to be arith? You can't declare variable names starting with a number, so 9 is wrong. Line 10 is also unnecessary, and ideally line 11 should be removed and function prototypes go into the global scope.

Inputting whether 1 or 2 for arithmetic/trigonometric should be done using just a single int, which you can then use an if statement to determine which function should be called. Also, in your code you neglected calling either of them...

For the trigonometric functions, it should work the same way. Preferably you should use a std::string to determine the function they want, but using an int and giving a list of numbered options is more appropriate for use with a switch statement.

If you have any more problems, feel free to ask. Also, make sure to test your code (always a good idea)!

Not just test your code, but test it in small bits - each code block, and even as you build code blocks, to make sure you didn't put a typo somewhere. If you're using a compiler with debug features, it's great, but you can use "poor-man's" debugging by cout << [expectedresult]; periodically, to check your results before continuing to add more programming.
Unfortunately, my professor did not teach us how to incorporate trig functions, so when it comes to Trig I am completely lost? Can anyone help me with that please :(?
I actually cleaned up my code a bit!!! I am just getting one error in Visual Studio that says :Error C: 1083 "Error 1 error C1083: Cannot open include file: 'header.hpp': No such file or directory

The code now is the following: #include "stdafx.h"
#include "header.hpp"
#include <math.h>
#include <iostream>
using namespace std;

int main () {
cout <<"Welcome to Robert's calculator." <<endl;
int arith(),trig();
}
int main ()
{
double Operand1, Operand2, Result;
char Operator;

cout <<"This Program allows you to perform an operation on two numbers\n";
cout <<"To proceed, enter a number, an operator, and a number\n";
cin >> Operand1 >> Operator >> Operand2;
}
switch (Operator)
{
case '+':
Result= Operand1 + Operand2;
break;

case '-':
Result= Operand1 - Operand2;
break;

case '*':
Result = Operand1 * Operand2;
break;

case '/':
Result = Operand1 / Operand2;
break;

}

cout <<"\n" <<Operand1 << " " << Operator << " "
<< Operand2 << " = " <<Result;

cout << "\n\n";


NOTE: Can someone please help me and tell me what I'm doing wrong to have the arithmetic portion of the calculator working? I would like to get that part completely right first before I proceed onto the Trignometric part. Again, any help at all I would appreciate it so much, as this assignment is due in the morning tomorrow!
You still haven't fixed a bunch of the things that I suggested. If you want, I'll show you how you can use functions:
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
#include <iostream>
#include <cmath>

// function prototypes
void arith();
void trig();

int main() {
    std::cout << "Welcome to Robert's Calculator.\n";
    
    int choice;
    std::cout << "Enter 1 for Arithmetic and 2 for Trigonometric: ";
    std::cin >> choice;

    if (choice == 1)
        arith();
    else if (choice == 2)
        trig();
    else
        std::cout << "That wasn't an option.\n";

    return 0;
}

void arith() {
    // ...
}

void trig() {
    // ...
}
Registered users can post here. Sign in or register to post.