You are viewing our Forum Archives. To view or take place in current topics click here.
Need Help With C++ Program
Posted:
Need Help With C++ ProgramPosted:
Status: Offline
Joined: Jun 22, 201113Year Member
Posts: 199
Reputation Power: 7
Status: Offline
Joined: Jun 22, 201113Year Member
Posts: 199
Reputation Power: 7
I will +rep if you will help me with the problem.
Here's what the output box says:
#include <iostream>
#include <math.h>
using namespace std;
int main()
{
float x, a, b, c, ans, ans2, y, z, k;
float *coe, *anscoe, *tempcoe, *fact;
int n, i, g, s = 0, m = 0, w = 0;
cout << "Enter the degree of the polynomial(the highest power): ";
cin >> n;
coe = new float[n];
anscoe = new float[n-1];
tempcoe = new float[n];
fact = new float[n];
for(i = n; i >= 0; i--)
{
if (i != 0)
{
cout << "The coefficient of x^" << i << ": ";
cin >> coe[i];
}
else
{
cout << "Enter the constant term: ";
cin >> coe[i];
}
}
for(i = 0; i <= n; i++)
{
tempcoe[i] = coe[i];
anscoe[n] = tempcoe[n];
g = n;
for (k = -50; k <= 50; k++)
{
for ( i = (n-1); i >= n-g; i--)
{
anscoe[i] = k*anscoe[i+1]+tempcoe[i];
}
if (anscoe[n-g] == 0)
{
cout << "Factor " << k <<" found." << endl;
fact[m++] = k;
w++;
for (i = 0; i <= n; i++)
{
tempcoe[i] = anscoe[i];
}
g--;
cout << "Remaining: ";
for (i = n; i >= n-g; i--)
{
cout << tempcoe[i] << "x^" << i - (n-g);
if (i != n-g)
cout <<" + ";
}
cout << endl;
k = k-1;
}
}
cout << "No whole factors remaining between [-50, 50]" << endl;
cout << "Remaining: ";
for (i = n; i >= n-g; i--)
{
cout << tempcoe[i] << "x^" << i - (n-g);
s++;
if (i != n-g)
cout <<" + ";
}
cout << endl;
if (w == n)
{
for (i = 0; i < n; i++)
fact[i] = fact[i] * -1;
}
else
{
for (i = 0; i <= n-w; i++)
fact[i] = fact[i] * -1;
}
if (s == 3)
{
for (i = n; i >= n-g; i--)
{
a = tempcoe[i+2];
b = tempcoe[i+1];
c = tempcoe[i];
}
y = ((b * b) - (4 * a * c));
z = sqrt(y);
ans = ((-b + z));
ans2 = ((-b - z));
ans = ans/(2 * a);
ans2 = ans2/(2 * a);
if (y < 0)
{
cout << "This factor is an imaginary answer" << endl;
if (w == n)
{
for (i = 0; i < n; i++)
{
if (fact[i] > 0)
cout << "Factor: (x +" << fact[i] << ")" << endl;
else
cout << "Factor: (x" << fact[i] << ")" << endl;
}
}
else
{
for (i = 0; i <= n-w; i++)
{
if (fact[i] > 0)
cout << "Factor: (x +" << fact[i] << ")" << endl;
else
cout << "Factor: (x" << fact[i] << ")" << endl;
}
}
cout << "Remaining Factor: ";
for (i = n; i >= n-g; i--)
{
cout << tempcoe[i] << "x^" << i - (n-g);
if (i != n-g)
cout << " + ";
}
cout << endl;
}
else
{
cout << endl;
cout << "The quadratic equation yields: " << endl;
cout << "x = " << ans << endl;
cout << "x = " << ans2 << endl;
cout << endl;
if (ans > 0)
cout << "Factor: (x +" << ans << ")" << endl;
else
cout << "Factor: (x" << ans << ")" << endl;
if (ans2 > 0)
cout << "Factor: (x +" << ans2 << ")" << endl;
else
cout << "Factor: (x" << ans2 << ")" << endl;
if (w == n)
{
for (i = 0; i < n; i++)
{
if (fact[i] > 0)
cout << "Factor: (x +" << fact[i] << ")" << endl;
else
cout << "Factor: (x" << fact[i] << ")" << endl;
}
}
else
{
for (i = 0; i < n-w; i++)
{
if (fact[i] > 0)
cout << "Factor: (x +" << fact[i] << ")" << endl;
else
cout << "Factor: (x" << fact[i] << ")" << endl;
}
}
}
}
else if (s < 3)
{
if (w == n)
{
for (i = 0; i < n; i++)
{
if (fact[i] > 0)
cout << "Factor: (x +" << fact[i] << ")" << endl;
else
cout << "Factor: (x" << fact[i] << ")" << endl;
}
}
else
{
for (i = 0; i <= n-w; i++)
{
if (fact[i] > 0)
cout << "Factor: (x +" << fact[i] << ")" << endl;
else
cout << "Factor: (x" << fact[i] << ")" << endl;
}
}
cout << "Factor: ";
cout << "(";
for (i = n; i >= n-g; i--)
{
cout << tempcoe[i] << "x^" << i -(n-g);
if (i != n-g)
cout << " + ";
}
cout << ")";
cout << endl;
}
else
{
cout << "This program cannot continue to factor this" << endl;
}
cin.get();
return 0;
}
Here's what the output box says:
1>------ Build started: Project: Factoring Equations, Configuration: Debug Win32 ------
1> Factoring Equations.cpp
1>c:\users\jordan\documents\visual studio 2010\projects\factoring equations\factoring equations\factoring equations.cpp(220): fatal error C1075: end of file found before the left brace '{' at 'c:\users\jordan\documents\visual studio 2010\projects\factoring equations\factoring equations\factoring equations.cpp(7)' was matched
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
#2. Posted:
Status: Offline
Joined: Jun 22, 201113Year Member
Posts: 199
Reputation Power: 7
Status: Offline
Joined: Jun 22, 201113Year Member
Posts: 199
Reputation Power: 7
Someone please help i will +rep you!!!!
- 0useful
- 0not useful
#3. Posted:
Status: Offline
Joined: Jul 12, 201014Year Member
Posts: 3,612
Reputation Power: 173
Status: Offline
Joined: Jul 12, 201014Year Member
Posts: 3,612
Reputation Power: 173
You are forgetting the end bracket mark silly. Just add "}" to the end of your code and it works fine.
- 0useful
- 0not useful
#4. Posted:
Status: Offline
Joined: Feb 23, 201212Year Member
Posts: 73
Reputation Power: 2
Status: Offline
Joined: Feb 23, 201212Year Member
Posts: 73
Reputation Power: 2
RDCA wrote You are forgetting the end bracket mark silly. Just add "}" to the end of your code and it works fine.
Haha so you are a wizard?
- 0useful
- 0not useful
#5. Posted:
Status: Offline
Joined: Jun 22, 201113Year Member
Posts: 199
Reputation Power: 7
Status: Offline
Joined: Jun 22, 201113Year Member
Posts: 199
Reputation Power: 7
Thank you so much i am so stupid lol.
- 0useful
- 0not useful
You are viewing our Forum Archives. To view or take place in current topics click here.