0

Code Blocks

Can you please help me out I need to create a simple calculator using if statement in code blocks that contains a modulus function.

19th Apr 2021, 3:40 PM
Huzaifa Bhyat
Huzaifa Bhyat - avatar
9 Answers
+ 1
//Calculator #include<iostream> using namespace std; int main() { float var1, var2, Result; //opt stands for operator char opt; cout << "Entre the first number" << endl; cin >> var1; cout << "Entre the secound number" << endl; cin >> var2; cout << "Entre operator (+,-,*,/,%)" << endl; cin >> opt; if (opt == '+') Result = var1 + var2; else if (opt == '-') Result = var1 - var2; else if (opt == '*') Result = var1 * var2; else if (opt == '/') Result = var1 / var2; else if (opt = '%') cout << "The remainder of " << var1 << "divided by " << var2; cout << " is " << var1 / var2 << " and has a remainder of " << var1 % var2 << endl; cout.precision(2); cout << " The result of " << var1 << " and " << var2 << " = " << Result; return 0; }
19th Apr 2021, 5:04 PM
Huzaifa Bhyat
Huzaifa Bhyat - avatar
+ 1
Use == in % operator also
19th Apr 2021, 5:49 PM
Atul [Inactive]
0
Okay, can you post your attempt?
19th Apr 2021, 3:58 PM
Slick
Slick - avatar
0
Please specify the language too
19th Apr 2021, 4:30 PM
Atul [Inactive]
0
Language C++
19th Apr 2021, 5:04 PM
Huzaifa Bhyat
Huzaifa Bhyat - avatar
0
This operator is giving me a problem %
19th Apr 2021, 5:05 PM
Huzaifa Bhyat
Huzaifa Bhyat - avatar
0
Thank you
19th Apr 2021, 7:41 PM
Huzaifa Bhyat
Huzaifa Bhyat - avatar
0
I tried it but it didn't work
20th Apr 2021, 2:03 PM
Huzaifa Bhyat
Huzaifa Bhyat - avatar