0

C++ using cin

Hello, i need some help for my first programm i would like to ask some number with cin>> but when i run my programm, the programm say no output and it's not what i want. Can you help me please ;)

15th Feb 2019, 5:42 PM
V1K0o
11 Respostas
15th Feb 2019, 5:43 PM
Anna
Anna - avatar
+ 1
Change if(delta = 0) to if(delta == 0). And you should possibly use floats or doubles instead of integers
15th Feb 2019, 6:03 PM
Anna
Anna - avatar
+ 1
Everywhere where you use int: int a => double a, int b => double b etc. Another problem is that you define delta right at the top, but you only get the values for a, b and c much later. When you calculate delta, a, b and c don't have values. So you should move the line cin >> a etc. up so that it comes before delta = (...)
15th Feb 2019, 6:28 PM
Anna
Anna - avatar
0
#include <iostream> #include <cmath> using namespace std; int main() { int a; int b; int c; int delta = (b*b)-(4*(a*c)); int racine_carre_de_delta = sqrt(delta); int x1= ((-b-racine_carre_de_delta)/2*a); int x2= ((-b+racine_carre_de_delta)/2*a); int x1bis= (-b/(2*a)); cout<< "Entrez a\n"; cout<< "Entrez b\n"; cout<< "Entrez c\n"; cin >> a >> b >> c; if (delta > 0) { cout<< "Deux solutions"; cout<< x1; cout<< x2; } if (delta = 0) { cout<< "Une solution"; cout<< x1bis; } if (delta < 0){ cout << "Pas de soltution"; } return 0; } There is here my programm thanks ;)
15th Feb 2019, 5:55 PM
V1K0o
0
Where i should put floats or doubles ?
15th Feb 2019, 6:09 PM
V1K0o
0
Ok thanks ;)
15th Feb 2019, 6:30 PM
V1K0o
0
#include <iostream> #include <cmath> using namespace std; int main() { double a; double b; double c; cout<< "Entrez a\n"; cout<< "Entrez b\n"; cout<< "Entrez c\n"; cin >> a >> b >> c; double delta = (b*b)-(4*(a*c)); double racine_carre_de_delta = sqrt(delta); double x1= ((-b-racine_carre_de_delta)/2*a); double x2= ((-b+racine_carre_de_delta)/2*a); double x1bis= (-b/(2*a)); if (delta > 0) { cout<< "Deux solutions"; cout<< x1; cout<< x2; } if (delta == 0) { cout<< "Une solution"; cout<< x1bis; } if (delta < 0){ cout << "Pas de soltution"; } return 0; } I switch like that but i can't enter numbers. The programm just run immediatly.
15th Feb 2019, 6:36 PM
V1K0o
0
It works for me đŸ€”
15th Feb 2019, 6:41 PM
Anna
Anna - avatar
0
When i should enter numbers and how. Maybe it's that?
15th Feb 2019, 7:02 PM
V1K0o
0
You have to enter all numbers right at the beginning when you run the program, with each number in a separate line: 2 1 5 This will assign the variable a the value 2, b the value 1 and c the value 5
15th Feb 2019, 7:07 PM
Anna
Anna - avatar
0
ok it works, but do yo know how to have not round numbers ?
15th Feb 2019, 7:21 PM
V1K0o