+ 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; }

27th May 2020, 6:36 AM
Viktor Kizera
Viktor Kizera - avatar
14 Antworten
+ 2
Yes I have done the same thing
27th May 2020, 7:03 AM
Namit Jain
Namit Jain - avatar
+ 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
27th May 2020, 6:58 AM
Arsenic
Arsenic - avatar
+ 2
Namit Jain And how to do it?
27th May 2020, 6:53 AM
Viktor Kizera
Viktor Kizera - avatar
27th May 2020, 6:56 AM
Namit Jain
Namit Jain - avatar
+ 2
Ohhhkk thanks Arsenic for the important info👍👍
27th May 2020, 7:01 AM
Namit Jain
Namit Jain - avatar
+ 2
Namit Jain Anything greater than 0 should be displayed "1", anything less than 0 is displayed "-1", if 0 then "0"
27th May 2020, 7:02 AM
Viktor Kizera
Viktor Kizera - avatar
+ 2
Arsenic Thank you very much, it works☺️
27th May 2020, 7:06 AM
Viktor Kizera
Viktor Kizera - avatar
+ 2
Everything is great, thank you ~ swim ~
27th May 2020, 7:43 AM
Viktor Kizera
Viktor Kizera - avatar
+ 1
Namit Jain I see, thank you very much)
27th May 2020, 7:07 AM
Viktor Kizera
Viktor Kizera - avatar
+ 1
Yes, everything is as you say) ~ swim ~
27th May 2020, 7:11 AM
Viktor Kizera
Viktor Kizera - avatar
+ 1
Sin Cara M You're Welcome😅
27th May 2020, 7:22 AM
Namit Jain
Namit Jain - avatar
+ 1
#include <stdio.h> int main() { int i; while(scanf("%d",&i)>0) { if(i==0) break; } printf("%d",i); return 0; }
27th May 2020, 5:03 PM
A S Raghuvanshi
A S Raghuvanshi - avatar
0
I do not understand why, but it closes in me as soon as I enter the number, and wrote everything as Arsenic , ~ swim ~
27th May 2020, 7:16 AM
Viktor Kizera
Viktor Kizera - avatar
- 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...
27th May 2020, 6:51 AM
Namit Jain
Namit Jain - avatar