Вопрос Помогите найти ошибку в программе написанной на C++ Visual Studio 2012.

Регистрация
2 Окт 2013
Сообщения
79
Репутация
0
Спасибо
0
Монет
0
Написал программу на Visual Studio 2012 (С++). Запустил её, но считается всё не верно. И выводится иногда бред типа: INFOO,00000000. Вместо этого бреда нужно вывести слово "Ошибка!"

Программа, собственно:
// Лабораторная_№4.cpp: определяет точку входа для консольного приложения.
//

#include "stdafx.h"
#include
#include
#include
#include
#include "conio.h"

double function1(double x)
{
return 1/sqrt(1 - x);
}

double function2(double x, double eps)
{
double sum = 0;
double x1 = x;
double f1, f2;
f1 = 1;
f2 = 1;
sum = f1 / f2;
int g = 2;
for (long int i = 2; fabs(f1 / f2) >= eps; i++)
{
f1 = f1*x1;
f2 = f2*g;
g += 2;
sum = sum - f1 / f2;
}

return sum;
}

double delta(double d1, double d2)
{
return sqrt(fabs(d1*d1 - d2*d2));
}

char bufRus[256];
char* Rus(const char* text)
{
CharToOemA(text, bufRus);
return bufRus;
}

int _tmain(int argc, _TCHAR* argv[])
{
using namespace std;
double xideal, x1, x2, step, f1, f2, eps;
setlocale(LC_CTYPE, "rus"); // вызов функции настройки локали
printf("Введите эпсилон: ");
cin >> eps;
while (eps <= 0)
{
printf("Введите эпсилон снова: ");
cin >> eps;
}
printf("Введите x1: ");
cin >> x1;
while (x1>1)
{
printf("Введите x1 снова: ");
cin >> x1;
}
printf("Введите x2: ");
cin >> x2;
while (x2>1)
{
printf("Введите x2 снова: ");
cin >> x2;
}
printf("Введите дельта x: ");
cin >> step;
while (step == 0)
{
printf("Введите дельта x снова: ");
cin >> step;
}
double xc, xe, step_;
xc = x1 * 100000;
xe = x2 * 100000;
step_ = step * 100000;
printf("+----------------------------------------------------------------------------+ ");
printf("| x | Функция 2 | Функция 1 | шаг | ");
printf("+----------------------------------------------------------------------------+ ");
if ((xc <= xe) && (step_ <= 0) || (xc >= xe) && (step_ >= 0))
{
printf("| %15.6lf |%16.6lf | %10.6lf |%10.6lf | ", x1, function2(x1, eps), function1(x1), delta(function2(x1, eps), function1(x1)));

}
else
if (xc <= xe)
{
for (xc; xc <= xe + 1; xc += step_)
{
if (xc <= xe)
{
printf("| %15.6lf |%15.6lf | %10.6lf |%10.6lf | ", x1, function2(x1, eps), function1(x1), delta(function2(x1, eps), function1(x1)));
}
x1 += step;
}
}
else
{
for (xc; xc >= xe - 10; xc = xc + step_)
{
printf("| %15.6lf |%15.6lf | %10.6lf |%10.6lf | ", x1, function2(x1, eps), function1(x1), delta(function2(x1, eps), function1(x1)));
x1 += step;
}
}
printf("+----------------------------------------------------------------------------+ ");
printf("Введите xideal: ");
cin >> xideal;
while (xideal >1)
{

printf("Введите xideal снова: ");
cin >> xideal;
}
printf("+----------------------------------------------------------------------------+ ");
printf("| эпсилон | Функция 2 | Функция 1 | шаг | ");
printf("+----------------------------------------------------------------------------+ ");
for (eps = 0.1; eps >= 0.000001; eps *= 0.1)
{
printf("| %15.6lf |%15.6lf | %10.6lf |%10.6lf | ", eps, function2(xideal, eps), function1(xideal), delta(function2(xideal, eps), function1(xideal)));
}
printf("+----------------------------------------------------------------------------+ ");
_getch();
}
//otvet.imgsmail.ru/download/52128439_f399ad03aabf924bd77f61ab4ac3bf26_120x120.png//otvet.imgsmail.ru/download/52128439_3afe3863e3bc7199bb2c5a45fbc09522_120x120.png
 
Назад
Сверху