@MrRangerYT

В чём может быть проблема Run-Time Check Failure #3?

#include "pch.h"
#include <iostream>
#include <math.h>
using namespace std;
const double eps = 0.00001;
double _pow(double a, double b) {
	double c = 1;
	for (int i = 0; i < abs(b); i++) c *= a;
	if (b < 0) c = 1 / c;
	return c;
}
double _fact(double x) {
	if (x < 0) return 0; 
	if (x == 0) return 1; 
	else return x * _fact(x - 1);
}
double _sin(double x) {
	double a = x, s = x;
	int n2 = 1;
	while (fabs(a) > eps){
		a = ((-a)*x*x) / ((n2 + 1)*(n2 + 2));
		s += a;
		n2 += 2;
	}
	return s;
}
double _cos(double x) {
	double a=1.0, s=0.0;
	int p = (int)s;
	while (fabs(a) > eps) {
		s += a;
		p++;
		a = ((-a)*x*x) / ((2 * p - 1)*(2 * p));
	}
	return s;
}
double _tan(double x) {
	return (_sin(x) / _cos(x));
}
double proverka(double x1,double x2) {
	int b=0, c=0;
	if (x1 + x2 != -b && x1*x2 != c) cout << NULL << endl;
	else cout << "1" << endl;
	return x1,x2;
}
int main() {
	cout << "Vvedite zadachu kotoruyu nado proverit :" << endl;
	int h;
	cout << "2ZADACHA-1" << endl; cout << "1ZADACHA-2" << endl;
	cin >> h;
	switch (h) {
	case 1: {
		cout << "Enter A, B, C:\n";
		int a = 0, b = 0, c = 0;
		cin >> a >> b >> c;
		double x1, x2;
		int discriminant = 0;
		discriminant = ((int)_pow(b, 2)) - 4 * a * c;
		if (discriminant > 0 && a != 0) {
			x1 = ((-b - sqrt(discriminant)) / 2 * a);
			x2 = ((-b + sqrt(discriminant)) / 2 * a);
			cout << x1 << x2 << endl;
		}
		else if (discriminant = 0 && a != 0) cout << "" << endl;
		else cout << "korney net" << endl;
		proverka(x1, x2);
		break;
	}
	case 2: {
		double x, a, b;
		int swtch;
		cout << "Vvedite chislo dlya vibora" << endl;
		cout << "SIN-1" << endl; cout << "COS-2" << endl; cout << "POW-3" << endl; cout << "TAN-4" << endl; cout << "FACT-5" << endl;
		cin >> swtch;
		switch (swtch)
		{
		case 1: {
			cout << "Vvedite x:" << endl; cin >> x;
			cout << "sin " << x << " = " << _sin(x);
			break;
		}
		case 2: {
			cout << "Vvedite x:" << endl; cin >> x;
			cout << "cos " << x << " = " << _cos(x);
			break;
		}
		case 3: {
			cout << "Vvedite a:" << endl; cin >> a;
			cout << "Vvedite stepen:" << endl; cin >> b;
			cout << "pow " << a << " s stepenyu" << b << " = " << _pow(a, b);
			break;
		}
		case 4: {
			cout << "Vvedite x:" << endl; cin >> x;
			cout << "tan " << x << " = " << _tan(x);
			break;
		}
		case 5: {
			cout << "Vvedite x:" << endl; cin >> x;
			cout << "FACT! " << x << " = " << _fact(x);
			break;
		}
		default:break;
		}
	default:break; }
	}
}
  • Вопрос задан
  • 126 просмотров
Пригласить эксперта
Ответы на вопрос 1
@sddvxd
Там написано "x2 был использован без инициализации"
Ответ написан
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Похожие вопросы