C :: Calculate The Solutions Of Quadratic Equations

Oct 22, 2014

I have a task to find errors in this long line of code in order to correctly calculate the solutions of quadratic equations.

Code:
int main(int argc, char *argv[]) {
int validInput, solution_type;
double a, b, c, root_1, root_2, q;

/***********************
* Input / Validation
***********************/

/* Check numbers of arguments, and read input */
validInput = (argc = 4);

[Code] ....

Is a section of the code (the first section). And as you can probably guess, it goes on to calculate for a > 0 etc...

I dont really understand what the validinput section is saying? And a, b and c are never defined so Xcode is just saying a,b,c,root1,root2 are uninitialized and I also dont know what means. Do I need to define these values?

Code:
int main(int argc, char *argv[]) {
int validInput, solution_type;
double a, b, c, root_1, root_2, q;

[Code] ......

View 9 Replies


ADVERTISEMENT

C++ :: Determine Roots Of Quadratic Equations?

May 23, 2013

I have given following exercise in my cpp book: Determine the roots of quadratic equations

ax^2 + bx + c = 0

using formula

x = -b +(plus-minus) (root)b^2 - 4ac/2a

i don't now how to write such code...

View 6 Replies View Related

C :: Calculate Equations Just Like A Standard Calculator

Oct 23, 2013

The main point of the program is to calculate equations just like a standard calculator but I wanted to do it myself. I don't understand what the problem is right now but I've managed to create a program that asks for both values but somehow it doesn't want to ask for an operator (*, /, + etc). What's wrong with my code that the terminal skips the scanning part for the operator?

Code:

#include <stdio.h>
int main() {
int value1, value2, answer;
char operator;

[code]....

View 12 Replies View Related

C++ :: Two Solutions For X And Y

May 7, 2014

I'm trying to write a code that will give me two solutions one for x and one for y.

The equation is the following x^2+4=y^3

The solution for y is y=(x^2+4)^1/3

The solution for x is x=(y^3+4)^1/2

The answer needs to printed like that in upper section. I've written a bad code, cause I'm not good at programing. But never the less it's a start, i think.

#include <iostream>
using namespace std;
int main () {
int a; //replaceable
int b; //replaceable
int ind_a=2; //upper index of a
int ind_b=3; //upper index of b

[code] .....

View 1 Replies View Related

C :: Quadratic Equation - ID Returned 1

Oct 18, 2013

This is my code:

Code:
#include <math.h>
#include <stdio.h>
int main(void) {
float a,b,c,root_1,root_2;
printf("Please enter value a from the quadratic equation

[Code] ......

And I keep getting this error:

Code:
/tmp/ccgtUIun.o: In function `main':
assign345.c:(.text+0xc7): undefined reference to `sqrt'
assign345.c:(.text+0xef): undefined reference to `sqrt'
collect2: ld returned 1 exit status

View 5 Replies View Related

C++ :: Quadratic Equation - Output Is NAN

Jul 4, 2014

soo quadratic equation solver. output is "x=nan x=nan".

#include <iostream>
#include <string>
#include <cmath>
using namespace std;
//prototyping
double ans_1(double,double,double)

[code].....

View 2 Replies View Related

C/C++ :: Quadratic Formula - If Statement Being Ignored

Jan 28, 2014

We are suppose to build a program to do the quadratic formula, which isnt really a issue. my issue is i have a if else loop and my if is being ignored.

what i want it to do is is state that if the (b * /> - 4(a)© is a negative, then it prints out stating it cant do this.

note: i know that i can use the i number system but we have been asked to not too and to do this instead.

here is my code

#include <stdio.h>
#include <math.h>
int main() {
float a, b, c, d, e, f, g, h, i; /* i would love to figure out a way to do this without so many variables*/

[code]....

View 3 Replies View Related

C :: Working With Equations

Nov 19, 2013

I need to find out all the possible equations which are same of a given equation. For eg. a+b+c-d and b+c+a-d are same. So if the user inputs a+b+c-d then the output will be all the possible equations that can be formed from the given equation, viz:

a+c+b-d
c+a+b-d
-d+a+c+b

etc

i.e the program should rearrange the operands and operators in such a way that it should give the same result.

View 5 Replies View Related

C :: Program To Solve The Quadratic Equation

Feb 3, 2013

I am creating a program that solves the quadratic equation ax^2 + bx +c.

I have this program almost complete except the output of the equation in the function called display_quadratic. I need the program to display the variables a,b,c in the equation ax^2 + bx + c but I am having 2 problems. My first problem is that I cannot get the right addition and subtraction signs for the equation.

For instance, if the program had the values for a,b,c as 2,2,3

it will display 2x^2 2x 3

How can I get it to display 2x^2 + 2x + 3? or if it was negative like 2x^2 - 2x - 3?

My next question is how do I get to not display the coefficients that are 1?

I had an if-else statement but no matter what I created it would overlap with another statement and print out twice. Here is the code:

Code:
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

void display_quadratic (float a, float b, float c);
float root1(float a, float b, float c);

[Code] ......

View 2 Replies View Related

C++ :: Quadratic Equation - No Matching If Statement

Oct 7, 2013

This is my code for the quadratic equation. It keeps telling me that my else is illegal since no matching if statement and my else statement is missing a statement

#include <iostream>
#include <cmath>
#include <string>
#include <iomanip>
using namespace std;
int main() {
string Name;

[Code] .....

View 3 Replies View Related

C++ :: Equations And Intersection Point

Aug 17, 2013

Program which accepts two lines and and determines their intersection point and whether they lie within a circle, also given interactively. I'm racing against time and I've racked my skull to no avail

View 2 Replies View Related

C++ :: Quadratic Formula Loss Of Significance And Simplification

Feb 16, 2015

write codes that could solve a quadratic formula, and my codes are like this:

#include <bjarne/std_lib_facilities.h>
int main()
{
cout << "Enter the coefficients of a quadratic polynomial a*x**2 + b*x +c:
";
cout << " a? ";
double a;
cin >> a;
cout << " b? ";

[code]....

Which runs perfectly, but I have 2 questions:

1. How to simplify these code? On the assignment sheet the professor wrote about using void solve_linear(double b, double c); and void solve_ quadratic (double a, double b, double c);which I currently dont understand how these works. He asked us to write a well-encapsulated (as short as possible) program.

2. These are for extra points: the precision problem of floating numbers: professor asked us to find a way to get the precise answer of it, like this: Enter the coefficients of a quadratic polynomial a*x**2 + b*x +c:
a? 1
b? -20000
c? 1.5e-9
Trying to solve the quadratic equation 1*x*x + -20000*x + 1.5e-09 == 0
Using classical formula: Two roots, x = 20000 and x = 0
Using stable formula: Two roots, x = 20000 and x = 7.5e-14

My guess is that
A. Using code like if(x1*x2=a/c) to check if numbers were approximated.
B. Somehow determine the larger one in x1 and x2.
C. Somehow use that larger one to do something

View 2 Replies View Related

C/C++ :: Quadratic Equation Solver - Simplification Function

Jul 6, 2014

So, I successfully made a program that will perform the quadratic equation on three numbers, imaginary or real. however, i am now trying to simplify the result, as to get rid of the "/2a" on the bottom. Hence the simplify() function. I just started to create the simplification function, and am attempting to divide the imaginary part of the solution as well as the real part of the solution by 2a. Somehow, it gives the error, "error:invalid operands of types 'int' and 'double *' to binary 'operator*'" on lines 105 and 106. I suspect it has to do with the pointers and references that i am passing as parameters. Also, just an aside, I have never actually seen "/=" be used. It can be, right? I know "+=" can be.

#include <iostream>
#include <string>
#include <cmath>
#include <cstdlib>//simplify the answer
using namespace std;
int count=0;
//prototyping
double ans_1(double,double,double);

[Code] ....

View 5 Replies View Related

C :: Program That Solves Math Equations

Apr 30, 2013

I wrote a program that solves an equation of two numbers, but in addition to that, I want it to be able to continue to solve longer equations. Ex: ( solves 2 * 4, or 2 * 4 - 5).I want to put this part of the program's result into a variable and go from there. How do I place the result of the calculation into a variable, and where would it go?

Code:

#include <stdio.h>
#include <string.h>
int main(void) {
int a;
scanf("%d", &a);
char s[2];
scanf("%s", s);
int b;
scanf("%d", &b);
}

[code]....

View 4 Replies View Related

C :: Scanning Equations / Functions Into Program

Nov 15, 2014

I have to make a numerical integration program, how I can write my code so that the user is able to write their own function that they want to integrate?

E.g. they would see the message: 'please enter your function' and would be able to write whatever they wanted e.g. 'x +5' then this would then be integrated by the program.

I have already written a program that can integrate a known function but would prefer that the user could choose their own.

View 2 Replies View Related

C++ :: Solving Linear System Of Equations Using Threads

Dec 14, 2014

I am trying to write a code that solves a system of linear equations such as A*B=C. My system has a dimension equal to 1600. The matrix A cab be separated into 4 sub matrices and each can be handled by a different thread. I tried to solve this using the following code:

int main() {
int count = 0;
//Inputing matrix A
ifstream matrix;
matrix.open("example.txt");

[Code] ....

Although the above code gives the correct answer, the time needs to find the solution is bigger than that needed without using threads.

View 1 Replies View Related

C++ :: Finite Difference Method For Partial Differential Equations?

Nov 10, 2013

Calculated by the explicit scheme. Produces some very large numbers.

task:

[math] U_t = 3 (1,1-0,5 x) U_ {xx} + e ^ t-1 [/ math]
[math] U (0, t) = 0 [/ math]
[math] U (1, t) = 0 [/ math]
[math] U (x, 0) = 0.01 (1-x) x [/ math]

Need to find a solution with accuracy [math] 0.0001 [/ math] on the interval [math] T = 1 / a ^ *, where a ^ * = max a (x, t) [/ math] Plot graphs of functions [math] u (x ^ *, t), u (x, jt ^ *) [/ math] where [math] x ^ * = 0.6, t ^ * = T/10, j = 1,2,4 [/ math]

explicit difference scheme is as follows:

([math] $ u_t ^ {j +1}-u_i ^ j) / tau = 3 (1,1-0,5 x_i) (u_ {i +1} ^ {j}-2u_i ^ j + u_ {i -1} ^ j) / h ^ 2 + e ^ {t_j} +1 $ $ [/ math]

code of the program:

int main ( void ) {
setlocale(LC_ALL, "rus");
int I = 10, J = 30, i, j;
double T = 1.0/ pow(3.3, 0.5), h_x = 1.0/ I, h_t = T/ J, epsilon = h_t + pow(h_x, 2), c;
double **u = new double *[I + 1];
for (i = 0; i <= I; i++) u[i] = new double [J + 1];

[code]....

displays the following:

[URL]

View 2 Replies View Related

Visual C++ :: Pthreads - Solve System Of Equations By Gauss-Jordan Method

Dec 15, 2012

I have a problem: solve the system of equations by the Gauss-Jordan methods with pthreads. I have a big matrix A (for example 2000x2000), so i must solve Ax = b. Before I devide matrix to number of threads and each thread must work only with his peace of matrix.

Code:
#include <iostream>
#include "synchronize.h"
#include <pthread.h>
using namespace std;
typedef struct _ARGS {
int thread_count;
int thread_number;

[Code] .....

I write it on Ubuntu, and when I compile [g++ main.cpp -o main -lpthread -lm] the it works good(for example, if in 1 thread I get time_of_working = 10 sec, on 2 threads time_of_working = 5.4, i.e. about 2 times faster ), if I compile like this [g++ main.cpp -o main -lpthread -lm -O3] it is only 1.2-1.3 times faster.

View 1 Replies View Related

C :: Calculate Approximate Value Of E

Jul 12, 2013

I'm trying to write a program to calculate an approximate value of e using the formula e = 1 + 1/1! + 1/2! + ....... 1/n!...However, I'm always getting nearly 2.291481 as answer.Here is my code :

Code:

//Approximate the value of e
#include <stdio.h>
int main(void) {
int n, j;
printf("Please enter value of n : ");
scanf("%d", &n);

[code]....

I know I'm not supposed to use system("PAUSE"), but this is self-study.

View 8 Replies View Related

C++ :: Program To Calculate BMI

Oct 7, 2013

I'm trying to successfully run a program that calculates your BMI but, although it runs, it is not giving the the correct math. Instead, it gives me the number i've submitted as my weight as an answer. I'm using Visual Studio 2008 and the formula: weight / (height/100)*2

Here is my code

#include <iostream>
#include <cmath>
using namespace std;
int main() {
int weight;
int height;
double BMI;

[Code] ....

View 2 Replies View Related

C++ :: Calculate Something More Than A Var Can Handle?

Jan 1, 2013

Let's say I want to calculate something like PI using some algorithm, but with the number of digits I want to.

View 1 Replies View Related

C/C++ :: Calculate Sum Of Every Digit

Nov 22, 2014

I want calculate sum of every digit in my zip code so I wrote implementation function like that but, it shows "0" as answers, then I realize it should be call first, I add correctionDigitOf() in to constructor "Zipcode::Zipcode" then My zipcode are all "0' after I do this .....

#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <ctime>
#include <cmath>
using namespace std;
class Zipcode {

[Code] ....

View 1 Replies View Related

C/C++ :: Contributions Will Not Calculate

Aug 7, 2012

Contributions won't calculate ...

#include <stdio.h> 
#include <conio.h> 
int main()  { 
float tax;
 float salary;
 float taxable;
 float taxmo;
 float contributions;

[Code] .....

View 1 Replies View Related

C++ :: Calculate Area Of Circle Without Pi

Mar 22, 2013

I was given an assignment for class to calculate the area of a circle using only the radius as a user input and not using Pi in the code. I need to do this by calculating the areas of a series of rectangles under the curve and adding them together. Using nested loops to continuously reduce the size of these rectangles until the approximated area value is within a margin of error less than 0.1%.

Code:
#include<iostream>
#include<cmath>
using namespace std;
int main ()

[Code] .....

View 7 Replies View Related

C++ :: Calculate The Angle Between Two Vectors

Feb 20, 2014

My question is not in c++ programing , but because my aim is to make code that calculate the three angles between two vector i ask my question here

So as the title i have three point that create two vector and I want to get the angles in x,y and z of the point2

I used crosproduct that give me one angle without axe , I don't know in which axe this angle

My aim is the three angles for the 3 axes ....

View 7 Replies View Related

C :: Algorithm To Calculate Highest Value?

Aug 3, 2014

Now I know there's a simple way to calculate highest value. But here i have this algorithm which i understood part of it.

I know that *largest is point to the first element of begin which is 5. so in the first if statement its 5<5 at the first iteration ?

// i marked the parts i didnt understand with " //"

Code:
#include <stdio.h>
int *print(int *begin ,int *end ){
if(begin==end)
return 0;
int *largest = begin;

[Code] ....

View 10 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved