+ 2
9th Nov 2020, 11:32 AM
Arash
Arash - avatar
5 Answers
+ 5
Arash Your program lacks Logic and many many things. The syntax for declaring and initializing a character variable is : char variable='+'; Also ,how can u compare the un-initialized variable "c" .
9th Nov 2020, 11:39 AM
Alphin K Sajan
Alphin K Sajan - avatar
+ 4
You can't just write char = '+'; because a variable needs an identifier, a name to access it. Therefore, you would have to give each of those a fitting name, e.g. char plus = '+'; ... However, you never really use them, so I don't see what their purpose is. Furthermore, a program is executed from top to bottom. If you want input from the user, you need to get it before doing anything with the variables you use to store that input. In your case, you try to use 'c' without giving it a value at all. Also, there is a stray 'i' on line 14, and the third if-statement lacks a closing brace.
9th Nov 2020, 11:40 AM
Shadow
Shadow - avatar
+ 1
#include <iostream> using namespace std; int main() { int a; int b; char c; cin>>c; if (c == '+'){ cin >>a>>b; cout<<a<<"+"<<b<<"="<<a+b; } if (c == '/'){ cin >>a>>b; cout<<a<<"/"<<b<<"="<<a/b; } if (c == '*'){ cin >>a>>b; cout<<a<<"*"<<b<<"="<<a* b;} if (c == '-'){ cin >>a>>b; cout<<a<<"-"<<b<<"="<<a- b; } return 0;} this is your solution, keep it up ,first learn language syntax than write code
9th Nov 2020, 11:40 AM
Prathvi
Prathvi - avatar
0
Many problems in your code
9th Nov 2020, 11:40 AM
Prathvi
Prathvi - avatar
0
This code was supposed to be a calculator. Now that I've changed it, hasn't he lost his problem?
9th Nov 2020, 5:05 PM
Arash
Arash - avatar