#include <iostream>
#include <cmath>
int main()
{
usingnamespace std;
int a;
int b;
int c;
int answer;
cout <<" Calculator !!! " << endl;
cout <<" Made by UdAy ShArMa the GREAT!!! " << endl;
cout <<" PLease ENTER your number. " << endl;
cin >> a;
cout << " PLease ENTER the operation. " << endl;
cin >> b;
cout << " PLease ENTER your other number. "<< endl;
cin >> c;
answer = a,b,c;
cout << " Your anSwer is "<< answer <<", OMG that's sooo cool. "<< endl;
return 0;
}
->It compile's and everything but it's out put is messed up. This is the output:
Calculator!!!
Made by UdAy ShArMa the GREAT!!!
Please ENTER your number.
123
PLease Enter your operation.
+
PLease ENTER your other number.
Your anSwer is 123, OMG that's sooo cool
Your second input is the symbol '+'. You are trying to store that symbol in a variable of type int.
The variable type int is for storing numbers. '+' is not a number. cin is trying to store a number in b, and you are breaking things by not putting in a number.
Note also that this answer = a,b,c;
makes no sense whatsoever.
#include <iostream>
#include <cmath>
int main()
{
usingnamespace std;
int a;
int b;
int c;
int addition;
int subtraction;
int multiplication;
int division;
int answer;
cout <<" Calculator !!! " << endl;
cout <<" Made by UdAy ShArMa the GREAT!!! " << endl;
cout <<" PLease ENTER your number. " << endl;
cin >> a;
cout << " PLease ENTER the operation(addition, subtraction, multiplication, division). " << endl;
cin >> b;
cout << " PLease ENTER your other number. " << endl;
cin >> c;
if (b = addition){
answer = a + b;
}
if (b = subtraction){
answer = a - b;
}
if (b = multiplication){
answer = a * b;
}
if (b = division){
answer = a / b;
}
cout << " Your anSwer is "<< answer <<", OMG that's sooo cool. "<< endl;
return 0;
}
Your second input is the symbol '+'. You are still trying to store that symbol in a variable of type int.
The variable type int is for storing numbers. '+' is not a number. cin is still trying to store a number in b, and you are breaking things by not putting in a number.
You have not changed anything. You are still trying to store something that is not a number in a variable that is meant only for storing numbers.
Looking at your code, I think you simply don't understand what a variable is (or possibly, you think there is only one kind of variable; int). You need to go back to the basics of what a variable is.
thanks for the advice so i looked it up in primer plus and i noticed char variables and studied them and so they store character variables so should i use them???
Calculator !!!
Made by UdAy ShArMa the GREAT!!!
PLease ENTER your number.
5
PLease ENTER the operation(1 addition,2 subtraction,3 multiplication,4 division).
2
PLease ENTER your other number.
3
Your anSwer is 3, OMG that's sooo cool.
I really see you getting things fast and do good work.
Here if you have used
switch functionality that would be much better.
You also need to learn to make your program robust,
for example think : what happens if in operation asking user enter the number which is not in the list......
And I am suggesting you switch case, because that is better way to do multiple if else conditions.
I guess you will soon post your new code using switch case and you should provide quit option after every operation, so that if you want to perform another operation you don't have to run program again and again...
#include <iostream>
int main()
{
usingnamespace std;
int number;
int number2;
int choice;
int answer;
//First Display
cout <<" Calculator !!! " << endl;
cout <<" made by uday sharma the great!!! " << endl;
cout <<" please enter a number. " << endl;
//Enter the information
cin >> number;
cout << " please enter the operation: (1) addition,(2) subtraction,(3) multiplication,(4) division. " << endl;
cin >> choice;
cout << " please enter another number. " << endl;
cin >> number2;
switch(choice)
{
//Addition
case 1:
answer = number + number2;
break;
//Subtraction
case 2:
answer = number - number2;
break;
//Multiplication
case 3:
answer = number * number2;
break;
//Division
case 4:
answer = number / number2;
break;
//Error
default:
cout << "Error: you did not enter a valid character";
break;
}
cout << " your answer is "<< answer <<", omg that's sooo cool. "<< endl;
return 0;
}
P.S. Sorry for changing variable names, it was easier for me to read that way.