Runescapian321
02-18-2008, 09:27 PM
I have to make a thing that solves quadratic equations. They gave me the algorithm, and I have to make the program. So here is what I have...
#include "stdafx.h"
#include "simpio.h"
#include "genlib.h"
#include <math.h>
int power(int num1,int num2)
{
int num3, num4,num5,num6, count;
count = 1;
num3 = num1;
num4 = num1;
num5 = num2;
num6 = num2;
if(num1<0)
{
num1=num1-num1-num1;
}
if(num2<0)
{
num2=num2-num2-num2;
}
while(count < num2)
{
num1 = num1 * num3;
count = count + 1;
num4 = num1;
}
if(num5<0)
{
if(num6=0)
{
num4=1;
}
}
else
{
if(num6==0)
{
num4=1;
}
return num4;
}
}
int step14(int b, int D, int a)
{
int x1,x2;
x1 = (-b + sqrt(D)) /2a;
x2 = (-b - sqrt(D)) /2a;
}
int solveit()
{
int a,b,c,D,x,x1,x2,num;
printf("Enter A: ");
a = GetInteger();
printf("Enter B: ");
b = GetInteger();
printf("Enter C: ");
c = GetInteger();
if (a == 0)
{
if (b == 0)
{
printf("no solution");
exit(0);
}
else
{
x = -c/b;
}
printf("the equation is not quadratic and the solution is: %d", x);
exit(0);
}
num = power(b,2);
D = num-4*a*c;
if (D<0)
{
printf("There is no real solution");
}
if (D==0)
{
step14(b,D,a);
exit(0);
}
x1 = -b/2a;
printf("One solution: %d", x1);
}
int main()
{
solveit();
}
But it gives me these Errors
1>c:\users\tadas\documents\visual studio 2005\myprojects\quad\quad\quad.cpp(63) : error C2668: 'sqrt' : ambiguous call to overloaded function
1> c:\program files\microsoft visual studio 8\vc\include\math.h(581): could be 'long double sqrt(long double)'
1> c:\program files\microsoft visual studio 8\vc\include\math.h(533): or 'float sqrt(float)'
1> c:\program files\microsoft visual studio 8\vc\include\math.h(128): or 'double sqrt(double)'
1> while trying to match the argument list '(int)'
1>c:\users\\documents\visual studio 2005\myprojects\quad\quad\quad.cpp(63) : error C2059: syntax error : 'bad suffix on number'
1>c:\users\\documents\visual studio 2005\myprojects\quad\quad\quad.cpp(63) : error C2146: syntax error : missing ';' before identifier 'a'
1>c:\users\\documents\visual studio 2005\myprojects\quad\quad\quad.cpp(64) : error C2668: 'sqrt' : ambiguous call to overloaded function
1> c:\program files\microsoft visual studio 8\vc\include\math.h(581): could be 'long double sqrt(long double)'
1> c:\program files\microsoft visual studio 8\vc\include\math.h(533): or 'float sqrt(float)'
1> c:\program files\microsoft visual studio 8\vc\include\math.h(128): or 'double sqrt(double)'
1> while trying to match the argument list '(int)'
1>c:\users\\documents\visual studio 2005\myprojects\quad\quad\quad.cpp(64) : error C2059: syntax error : 'bad suffix on number'
1>c:\users\\documents\visual studio 2005\myprojects\quad\quad\quad.cpp(64) : error C2146: syntax error : missing ';' before identifier 'a'
1>c:\users\\documents\visual studio 2005\myprojects\quad\quad\quad.cpp(103) : error C2059: syntax error : 'bad suffix on number'
1>c:\users\\documents\visual studio 2005\myprojects\quad\quad\quad.cpp(103) : error C2146: syntax error : missing ';' before identifier 'a'
I dont understand the C2059 error (I assume the C2146 will be fixed once I fix C2059), and the sqrt error confuses me. I tried making D a double and making it 'double sqrt(D)', but then it gave me a bunch of new errors.
And also a question with 'exit(0)'. When I use that will the program exit out of the procedure it's in, will it exit out of the program, or will it do something else entirely?
Thanks in advance :)
#include "stdafx.h"
#include "simpio.h"
#include "genlib.h"
#include <math.h>
int power(int num1,int num2)
{
int num3, num4,num5,num6, count;
count = 1;
num3 = num1;
num4 = num1;
num5 = num2;
num6 = num2;
if(num1<0)
{
num1=num1-num1-num1;
}
if(num2<0)
{
num2=num2-num2-num2;
}
while(count < num2)
{
num1 = num1 * num3;
count = count + 1;
num4 = num1;
}
if(num5<0)
{
if(num6=0)
{
num4=1;
}
}
else
{
if(num6==0)
{
num4=1;
}
return num4;
}
}
int step14(int b, int D, int a)
{
int x1,x2;
x1 = (-b + sqrt(D)) /2a;
x2 = (-b - sqrt(D)) /2a;
}
int solveit()
{
int a,b,c,D,x,x1,x2,num;
printf("Enter A: ");
a = GetInteger();
printf("Enter B: ");
b = GetInteger();
printf("Enter C: ");
c = GetInteger();
if (a == 0)
{
if (b == 0)
{
printf("no solution");
exit(0);
}
else
{
x = -c/b;
}
printf("the equation is not quadratic and the solution is: %d", x);
exit(0);
}
num = power(b,2);
D = num-4*a*c;
if (D<0)
{
printf("There is no real solution");
}
if (D==0)
{
step14(b,D,a);
exit(0);
}
x1 = -b/2a;
printf("One solution: %d", x1);
}
int main()
{
solveit();
}
But it gives me these Errors
1>c:\users\tadas\documents\visual studio 2005\myprojects\quad\quad\quad.cpp(63) : error C2668: 'sqrt' : ambiguous call to overloaded function
1> c:\program files\microsoft visual studio 8\vc\include\math.h(581): could be 'long double sqrt(long double)'
1> c:\program files\microsoft visual studio 8\vc\include\math.h(533): or 'float sqrt(float)'
1> c:\program files\microsoft visual studio 8\vc\include\math.h(128): or 'double sqrt(double)'
1> while trying to match the argument list '(int)'
1>c:\users\\documents\visual studio 2005\myprojects\quad\quad\quad.cpp(63) : error C2059: syntax error : 'bad suffix on number'
1>c:\users\\documents\visual studio 2005\myprojects\quad\quad\quad.cpp(63) : error C2146: syntax error : missing ';' before identifier 'a'
1>c:\users\\documents\visual studio 2005\myprojects\quad\quad\quad.cpp(64) : error C2668: 'sqrt' : ambiguous call to overloaded function
1> c:\program files\microsoft visual studio 8\vc\include\math.h(581): could be 'long double sqrt(long double)'
1> c:\program files\microsoft visual studio 8\vc\include\math.h(533): or 'float sqrt(float)'
1> c:\program files\microsoft visual studio 8\vc\include\math.h(128): or 'double sqrt(double)'
1> while trying to match the argument list '(int)'
1>c:\users\\documents\visual studio 2005\myprojects\quad\quad\quad.cpp(64) : error C2059: syntax error : 'bad suffix on number'
1>c:\users\\documents\visual studio 2005\myprojects\quad\quad\quad.cpp(64) : error C2146: syntax error : missing ';' before identifier 'a'
1>c:\users\\documents\visual studio 2005\myprojects\quad\quad\quad.cpp(103) : error C2059: syntax error : 'bad suffix on number'
1>c:\users\\documents\visual studio 2005\myprojects\quad\quad\quad.cpp(103) : error C2146: syntax error : missing ';' before identifier 'a'
I dont understand the C2059 error (I assume the C2146 will be fixed once I fix C2059), and the sqrt error confuses me. I tried making D a double and making it 'double sqrt(D)', but then it gave me a bunch of new errors.
And also a question with 'exit(0)'. When I use that will the program exit out of the procedure it's in, will it exit out of the program, or will it do something else entirely?
Thanks in advance :)