Mar 26, 2017 at 10:00pm
There are errors in my code at lines 37 and 40 and i'm not sure how to fix them/ what I did wrong
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
|
#include <fstream>
#include <iostream>
#include <math.h>
#include <stdlib.h>
#include <iomanip>
using namespace std;
int main(void)
{
double epsilon = .00000001, a, b, i, x0, x1;
char zzz;
const char filepath[] = "C:\\CoutputFiles\\File3.txt";
const char ErrorMessage[] = "Can't open file ";
fstream OutStream(filepath, ios::out);
if (OutStream.fail())
{
cerr << ErrorMessage << filepath;
cin >> zzz;
exit(-1);
}
cout << "Program will approximate the square root of a number + 40\n\n";
cout << "Type in the last 2 digits of your University X number:\n";
cin >> a;
b = a + 40;
cout << "\nYou entered: " << a;
OutStream << "You entered: " << a << "\n";
cout << "\nFinding the square root of " << b;
cout << "\n\nList of steps with approximations: ";
if (a < 0.0);
system("pause");
{
cout << "Cannot find square root of a negative number...";
}
{
else (int i = 1);
x0 = b;
x1 = (x0 + b / x0) / 2;
while (fabs(x1 - x0)) > epsilon)
{
(x0 = x1;);
x1 = (x0 + b / x0) / 2;
cout << "\nStep " << i << ": " << x1;
OutStream << i << ", " << x1 << ", ";
i++;
}
cout << "\nThe square root of " << b << "is " << x1;
OutStream << "\nThe square root of " << b << "is " << x1;
}
OutStream.close();
cout << "\nPress any character then 'Enter'...";
cin >> zzz;
return 0;
}
|
Last edited on Mar 26, 2017 at 10:05pm
Mar 26, 2017 at 10:10pm
i think this:
invert line 32 with line 33 and delete semicolon at end of line 31;
delete line 41 ;
also a brace between those present in the lines 36 or 48 or 51 , it is useless
Last edited on Mar 26, 2017 at 10:15pm