**New course!**Every coder should learn

**Generative AI!**

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 ;)

11 Answers

+ 2

Please show your code
https://www.sololearn.com/discuss/1316935/?ref=app

+ 1

Change if(delta = 0) to if(delta == 0). And you should possibly use floats or doubles instead of integers

+ 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 = (...)

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 ;)

0

Where i should put floats or doubles ?

0

Ok thanks ;)

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.

0

It works for me 🤔

0

When i should enter numbers and how. Maybe it's that?

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

0

ok it works, but do yo know how to have not round numbers ?