Apologies if this is a silly question but I'm extremely new to coding, just started today.
I have searched the forums for a solution and they all seem to be people using the wrong variable type.
I'm trying to create a very simple calculator based around the language I currently know after three~ hours.
In order to do this, I am defining seven variables at the top, two will be input by the user as the numbers which will be calculated with.
The next one will be input by the user, as the operation they wish to perform.
The last four will be simple operators (+. -, *, /)
I'm planning to use if statements and a process of elimination to figure out which operator the user wishes to use.
My problem lies with defining the char variables. Now, correct me if I'm wrong but a char is able to hold one character such as a letter, symbol or number. However when I try to assign a value to the variable I get the error in the topic title.
(the code is unfinished and riddled with errors, I know. Trying to solve them one at a time)
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
|
#include <iostream>
using namespace std;
int main()
{
//Variables
double FirstNumber;
double SecondNumber;
char Operator;
char Add;
char Subtract;
char Multiply;
char Divide;
char Test = "a"
Add = "+"
Subtract = "-"
Multiply = "*"
Divide = "/"
//Assigning numbers to the variables
cout << "First number : ";
cin >> FirstNumber;
cout << "\nSecond number : ";
cin >> SecondNumber;
//Choosing the operator
cout << "\nNow, choose an operator : ";
cin >> Operator;
if (Operator == "+")
{
cout << FirstNumber + SecondNumber endl;
}
else
{
}
}
|