Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <iomanip>
- #include <string>
- int precision = 15;
- using namespace std;
- bool processAnswer(string answer)
- {
- return answer == "y" || answer == "Y";
- }
- double doCalculations(double a)
- {
- int i;
- double s = 1;
- if (a >= 0)
- {
- for (i = 2; i <= 8; i += 2)
- {
- s *= i * i;
- }
- s -= a;
- }
- else
- {
- for (i = 3; i <= 9; i += 3)
- {
- s *= (i - 2);
- }
- }
- return s;
- }
- int main(int argc, char ** argv)
- {
- system(" chcp 1251 > nul");
- bool isFinished; //условие многократной работы программы
- string answer;
- double a, s;
- do
- {
- cout << "Что-то надо ввести: ";
- cin >> a;
- s = doCalculations(a);
- cout << setprecision(precision) << s;
- cout << endl<<"Продолжить работу? (y,n)"; //многократная работа
- cin >> answer;
- isFinished = processAnswer(answer);
- }
- while (isFinished);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement