homework help

hello everyone,
i need help with my homework. i will appreciate your knowledge and help with my problem i have. i cannot get my program to work. i need to ask a user to input an operator and two operands. example "+, -, *, or /" and two numbers.

ex] *, 5, 5,
output 5 * 5 = 25

the following is what i have so far.
issues:
in function void ProcessAndDisplay(int firstNumber, int secondNumber, int total)
'operators': undeclared identifier
thank you for you help
-------------------------------------------------------

#include<iostream>
using namespace std;

void GetData(char&, int&, int&);
void ProcessAndDisplay(int, int, int);

int main()
{
char operators;
int firstNumber,
secondNumber,
total;

//**************************** Input ******************************

GetData(operators, firstNumber, secondNumber);

//********************* Process and Display ***********************

ProcessAndDisplay(firstNumber, secondNumber, total);


return 0;
}

void GetData(char& operand, int& firstNumber, int& secondNumber)
{
cout << "Please type one of the following operators and press ENTER ( *, /, -, + ) ";
cin >> operand;
cout << endl;
cout << "Type a number and press enter ==> ";
cin >> firstNumber;
cout << "Type another number and press enter ==> ";
cin >> secondNumber;
cout << endl;
}
void ProcessAndDisplay(int firstNumber, int secondNumber, int total)
{

if (operators == '+')
{
total = firstNumber + secondNumber;
cout << firstNumber << " + " << secondNumber << " = " << total << endl;
}
else if (operators == '-')
{
total = firstNumber - secondNumber;
cout << firstNumber << " - " << secondNumber << " = " << total << endl;
}
else if (operators == '*')
{
total = firstNumber * secondNumber;
cout << firstNumber << " * " << secondNumber << " = " << total << endl;
}
else if (operators == '/')
{
total = firstNumber / secondNumber;
cout << firstNumber << " / " << secondNumber << " = " << total << endl;
}
else
cout << "Operator must be one of the following ( *, /, -, + )." << endl;
}
The error is telling you exactly what it looks like it is: not a single place in ProcessAndDisplay is there any definition for the (variable?) called "operators".
God, code tags man... But yea. Look into scope of variables.
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
/* i need to ask a user to input an operator and two operands. example "+, -, *, or /" and two numbers.

ex. *, 5, 5,
output 5 * 5 = 25*/

#include <iostream>
using namespace std;

void multiply();
void division();
void addition();
void subtraction();
void printf();

int first = 0;
int second = 0;
int total = 0;

int main(){
    char userInput[1];
    while (true){
        cout << "Key in one of the following (0 to quit) and press ENTER:" << endl << endl;
        cout << "* Multiplication" << endl;
        cout << "\\ Division" << endl;
        cout << "+ Addition" << endl;
        cout << "- Subtraction" << endl;

        cin >> userInput;

        cout << endl;

        if (userInput[0] == '0')
            break;
        if (userInput[0] == '*')
            multiply();
        if (userInput[0] == '\\')
            division();
        if (userInput[0] == '+')
            addition();
        if (userInput[0] == '-')
            subtraction();
        else
            cout << endl;
    }
    return 0;
}

void multiply(){
    cout << "Key in fisrt number: ";
    cin >> first;
    cout << "Key in second number: ";
    cin >> second;
    total = first * second;
    cout << endl << first << " * " << second << " = " << total << endl;
}

void division(){
    cout << "Key in fisrt number: ";
    cin >> first;
    cout << "Key in second number: ";
    cin >> second;
    total = first / second;
    cout << endl << first << " // " << second << " = " << total << endl;
}

void addition(){
    cout << "Key in fisrt number: ";
    cin >> first;
    cout << "Key in second number: ";
    cin >> second;
    total = first + second;
    cout << endl << first << " + " << second << " = " << total << endl;
}

void subtraction(){
    cout << "Key in fisrt number: " << endl;
    cin >> first;
    cout << "Key in second number: " << endl;
    cin >> second;
    total = first - second;
    cout << first << " - " << second << " = " << total << endl;
}


im bored -_-
nd i'm a noob.. js
Last edited on
thank you guys for all your help. i will study your comments so i can understand C++. thanks again and God bless.
Topic archived. No new replies allowed.