+ 2
I enter numbers in the console, press Enter, and it closes immediately
#include <iostream> #include <string> #include <conio.h> using namespace std; int main() { int number; cout << "Enter a number: "; cin >> number; cout << endl; if (number > 0) { cout << "1"; } else if (number == 0) { cout << "0"; } else if (number < 0) { cout << "-1"; } getch(); return 0; }
14 Respostas
+ 2
Yes I have done the same thing
+ 4
Namit Jain (if else) is very much supported feature in C++. đ
https://code.sololearn.com/cK46a8054SDU/?ref=app
And Sin Cara M as far as problem is conserned in your code then it is nothing just that you are using outdated C++ headers(conio.h) which is no longer a standard header.
Here is the fix of your codeđ
https://code.sololearn.com/cz9PM5k9Nw0L/?ref=app
+ 2
Namit Jain And how to do it?
+ 2
Ohhhkk thanks Arsenic for the important infođđ
+ 2
Namit Jain Anything greater than 0 should be displayed "1", anything less than 0 is displayed "-1", if 0 then "0"
+ 2
Arsenic Thank you very much, it worksâșïž
+ 2
Everything is great, thank you ~ swim ~
+ 1
Namit Jain I see, thank you very much)
+ 1
Yes, everything is as you say) ~ swim ~
+ 1
Sin Cara M You're Welcomeđ
+ 1
#include <stdio.h>
int main() {
int i;
while(scanf("%d",&i)>0)
{
if(i==0)
break;
}
printf("%d",i);
return 0;
}
- 2
I don't think 'else if' is anything in C++
C++ has only if and else
C has if/else if/else
So according to me you will have to make nested conditions to make it work correctly...