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.
9 ответов
+ 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;
}
+ 1
Use == in % operator also
0
Okay, can you post your attempt?
0
Please specify the language too
0
Language C++
0
This operator is giving me a problem %
0
Thank you
0
I tried it but it didn't work