Answer the question
In order to leave comments, you need to log in
How can I add the calculation of degrees, percentages ... to the program code?
Hello. How can I add to the calculator the calculation of powers, percentages, arithmetic mean and some other functions in which it will be possible to select numbers manually? How can I clear the console of extra text? How can I make the program start again after each calculation? Thank you!
#include "pch.h"
#include <iostream>
#include <math.h>
#include <cstdlib>
#include <string>
using namespace std;
int main()
{
float a, b, c;
char x;
cout << "Calculator v0.1\n";
cout << "\n";
cout << "Write a symbol(+, -, *, /): ";
cin >> x;
cout << "Write a first number: ";
cin >> a;
cout << "Write a second number: ";
cin >> b;
if (x == '+')
{
c = a + b;
cout << "\n";
cout << "Answer: " << a << '+' << b << '=' << c << endl;
}
if (x == '-')
{
c = a - b;
cout << "\n";
cout << "Answer: " << a << '-' << b << '=' << c << endl;
}
if (x == '*')
{
c = a * b;
cout << "\n";
cout << "Answer: " << a << '*' << b << '=' << c << endl;
}
if (x == '/')
{
c = a / b;
cout << "\n";
cout << "Answer: " << a << '/' << b << '=' << c << endl;
}
cout << " \n";
return 0;
}
Answer the question
In order to leave comments, you need to log in
Clearing depends on the terminal. Usually on linux this is clear. In powershell, too, like
A operations, also introduce new operation icons like ^ for degree or % for percentages, m for average, etc. For the average, right in case 'm': you can add additional values.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question