HelpNeed help trying to figure this

Posts 1–11 of 11 · Page 1 of 1
Need help trying to figure this
I started C programming recently for classes, ive tried to program on C b4 but didnt investigate much further.
Now im learning it and I need help


This is a program that vises to calculate a quadratic equation.

The formula goes like ax^2+bx+c=0
The results are rp and rn.

Code:
#include <stdio.h>

int main(void) {
	float a; //Value for first variable of the equation 
	float b; //Value for second variable
	float c; //Value for third variable
	float rp; //First result of the equation, if the signal is +
	float rn; //Second result of the equation, if the signal is -
	
	printf("EQUAÇÂO QUADRATICA tipo ax^2+bx+c=0"); //Displays the formula
	printf("Insira a coordenada para o a. %f /n"); //Asks for the first variable
	scanf("%f", &a); 
	printf("Insira a coordenada para o b. %f /n"); //Second variable
	scanf("%f", &b);
	printf("Insira a coordenada para o c. %f /n"); //Third Variable
	scanf("%f", &c);
	rp=((-b)+sqrt((b*b)-(4*a*c)))/(2*a); // equation to calculate one value for x
	rn=((-b)-sqrt((b*b)-(4*a*c)))/(2*a); // equation of the second value for x
	
	printf("A variável x toma como valores: %f\n", rp ,rn) //Displays the results
	
	return 0;
}
What's wrong with it? Can you help me?
Thanks in advance.
Maybe you could tell us WHAT the problem is, and we will tell you WHY.
.................................................. .
Quote Originally Posted by Mokou-Sama View Post
I started C programming recently for classes, ive tried to program on C b4 but didnt investigate much further.
Now im learning it and I need help


This is a program that vises to calculate a quadratic equation.

The formula goes like ax^2+bx+c=0
The results are rp and rn.

Code:
#include <stdio.h>

int main(void) {
	float a; //Value for first variable of the equation 
	float b; //Value for second variable
	float c; //Value for third variable
	float rp; //First result of the equation, if the signal is +
	float rn; //Second result of the equation, if the signal is -
	
	printf("EQUAÇÂO QUADRATICA tipo ax^2+bx+c=0"); //Displays the formula
	printf("Insira a coordenada para o a. %f /n"); //Asks for the first variable
	scanf("%f", &a); 
	printf("Insira a coordenada para o b. %f /n"); //Second variable
	scanf("%f", &b);
	printf("Insira a coordenada para o c. %f /n"); //Third Variable
	scanf("%f", &c);
	rp=((-b)+sqrt((b*b)-(4*a*c)))/(2*a); // equation to calculate one value for x
	rn=((-b)-sqrt((b*b)-(4*a*c)))/(2*a); // equation of the second value for x
	
	printf("A variável x toma como valores: %f\n", rp ,rn) //Displays the results
	
	return 0;
}
What's wrong with it? Can you help me?
Thanks in advance.
You start out with the quadratic:
ax² + bx + c = 0

You want to divide by 'a'
x² + (b/a)x + c/a = 0

Put the constant on the other side
x² + (b/a)x = −c/a

Complete the square...
x² + (b/a)x + (b/2a)² = −c/a + (b/2a)²

Factor the left side:
(x + (b/2a))² = −c/a + (b/2a)²

Simplify:
(x + (b/2a))² = (b/2a)² − c/a

(x + (b/2a))² = b²/(4a²) − c/a

(x + (b/2a))² = b²/(4a²) − (4ac)/(4a²)

(x + (b/2a))² = (b² − 4ac) / (4a²)

Square root to isolate 'x'
x + (b/2a) = ±√[ (b² − 4ac) / (4a²) ]

x + (b/2a) = ±√[ b² − 4ac ] / (2a)

x = −(b/2a) ±√[ b² − 4ac ] / (2a)

x = [ −b ±√( b² − 4ac ) ] / (2a)
Quote Originally Posted by Mokou-Sama View Post
I started C programming recently for classes, ive tried to program on C b4 but didnt investigate much further.
Now im learning it and I need help


This is a program that vises to calculate a quadratic equation.

The formula goes like ax^2+bx+c=0
The results are rp and rn.

Code:
#include <stdio.h>

int main(void) {
	float a; //Value for first variable of the equation 
	float b; //Value for second variable
	float c; //Value for third variable
	float rp; //First result of the equation, if the signal is +
	float rn; //Second result of the equation, if the signal is -
	
	printf("EQUAÇÂO QUADRATICA tipo ax^2+bx+c=0"); //Displays the formula
	printf("Insira a coordenada para o a. %f /n"); //Asks for the first variable
	scanf("%f", &a); 
	printf("Insira a coordenada para o b. %f /n"); //Second variable
	scanf("%f", &b);
	printf("Insira a coordenada para o c. %f /n"); //Third Variable
	scanf("%f", &c);
	rp=((-b)+sqrt((b*b)-(4*a*c)))/(2*a); // equation to calculate one value for x
	rn=((-b)-sqrt((b*b)-(4*a*c)))/(2*a); // equation of the second value for x
	
	printf("A variável x toma como valores: %f\n", rp ,rn) //Displays the results
	
	return 0;
}
What's wrong with it? Can you help me?
Thanks in advance.
printf("A variável x toma como valores: %f\n", rp ,rn)";"<---- //Displays the results
Quote Originally Posted by abuckau907 View Post
Maybe you could tell us WHAT the problem is, and we will tell you WHY.
Quote Originally Posted by 42trojan42 View Post
printf("A variável x toma como valores: %f\n", rp ,rn)";"<---- //Displays the results
Cmon guys dont laugh, I am complete noob here.
I wanted to do quadratic equation calculator on my own, and I was writing these lines and gave me the errors:

[CODE]
[COLOR=red !important]Compilation error #stdin compilation error #stdout 0s 0KB comments (0)

stdincopy

Standard input is empty

compilation infoprog.c: In function ‘main’:
prog.c:12:2: warning: format ‘%f’ expects a matching ‘double’ argument [-Wformat
printf("Insira a coordenada para o a. %f /n");
^
prog.c:14:2: warning: format ‘%f’ expects a matching ‘double’ argument [-Wformat
printf("Insira a coordenada para o b. %f /n");
^
prog.c:16:2: warning: format ‘%f’ expects a matching ‘double’ argument [-Wformat
printf("Insira a coordenada para o c. %f /n");
^
prog.c:21:2: warning: too many arguments for format [-Wformat-extra-args]
printf("A variável x toma como valores: %f\n", rp ,rn)
^
prog.c:23:2: error: expected ‘;’ before ‘return’
return 0;
^
prog.c:24:1: warning: control reaches end of non-void function [-Wreturn-type]
}
^
stdout

[/COLOR]
Quote Originally Posted by Mokou-Sama View Post



Cmon guys dont laugh, I am complete noob here.
I wanted to do quadratic equation calculator on my own, and I was writing these lines and gave me the errors:

[CODE]
[COLOR=red !important]Compilation error #stdin compilation error #stdout 0s 0KB comments (0)

stdincopy

Standard input is empty

compilation infoprog.c: In function ‘main’:
prog.c:12:2: warning: format ‘%f’ expects a matching ‘double’ argument [-Wformat
printf("Insira a coordenada para o a. %f /n");
^
prog.c:14:2: warning: format ‘%f’ expects a matching ‘double’ argument [-Wformat
printf("Insira a coordenada para o b. %f /n");
^
prog.c:16:2: warning: format ‘%f’ expects a matching ‘double’ argument [-Wformat
printf("Insira a coordenada para o c. %f /n");
^
prog.c:21:2: warning: too many arguments for format [-Wformat-extra-args]
printf("A variável x toma como valores: %f\n", rp ,rn)
^
prog.c:23:2: error: expected ‘;’ before ‘return’
return 0;
^
prog.c:24:1: warning: control reaches end of non-void function [-Wreturn-type]
}
^
stdout

[/COLOR]
Dude u forgot the ; in the line 20 ...
also,

http://www.cprogramming.com/tutorial...t-strings.html

each %f or %e or %whatever is replaced by 1 value

printf("%d", var1, var2); // invalid, we're trying to put 2 variable into 1 place holder - printf not made to do this.

aka "prog.c:21:2: warning: too many arguments for format [-Wformat-extra-args]
printf("A variável x toma como valores: %f\n", rp ,rn)"

only 1 %f, can only output 1 variable.
Quote Originally Posted by abuckau907 View Post
also,

http://www.cprogramming.com/tutorial...t-strings.html

each %f or %e or %whatever is replaced by 1 value

printf("%d", var1, var2); // invalid, we're trying to put 2 variable into 1 place holder - printf not made to do this.

aka "prog.c:21:2: warning: too many arguments for format [-Wformat-extra-args]
printf("A variável x toma como valores: %f\n", rp ,rn)"

only 1 %f, can only output 1 variable.
Dude i need too much time to understand what you say more than converting binary to letters so mysterious
Quote Originally Posted by 42trojan42 View Post
Dude i need too much time to understand what you say more than converting binary to letters so mysterious
totes .
Guys I got it.
I noticed some shit I did wrong, and I also realised that there isnt always a solution for the equation (I knew it before but didnt write it on the code)

so here's the code well and working:

Code:
int main(void) 
{


float a;
float b;
float c;
float rp;
float rn;
 
printf("EQUAÇAO QUADRATICA tipo ax^2+bx+c=0  \n");
printf("Insira a coordenada para o a. \n");
scanf("%f", &a);
printf("Insira a coordenada para o b. \n");
scanf("%f", &b);
printf("Insira a coordenada para o c. \n");
scanf("%f", &c);
 
//Verificar se a equação tem solução !!
	if ((b*b)-(4*a*c)/(2.0*a) > 0) {
		rp=(-b)+sqrt((b*b)-(4*a*c)/(2*a));
		rn=(-b)-sqrt((b*b)-(4*a*c)/(2*a));
	printf("A variavel x toma como valores: %f e %f \n", rp ,rn);
        }
  else printf("Equação sem solução para os parâmetros introduzidos !\n");
return 0;
}
Posts 1–11 of 11 · Page 1 of 1

Post a Reply

Similar Threads

Talk with us