Write the program). Do not know how to make. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3

Write the program). Do not know how to make.

Write the program). Do not know how to make. Write the program). Do not know how to make. Write the program, with an integer, defined by his character, and the result was printed. If a positive number then 1, if the negative is-1, if 0 then 0 Code👇 #include <iostream> #include <string> using namespace std; int main() { int number; std:cout << "Enter a number:"; if (number > 0) { cout << "1"; } else if (number == 0) { cout << "0"; } else(number < 0); { cout << "-1"; } system("pause"); return 0; } Does not work((

26th May 2020, 6:48 PM
Viktor Kizera
Viktor Kizera - avatar
36 Answers
+ 7
Look at std:cout ,it should be std:: cout and you aren't asking for any user input ? std::cin>>number;
26th May 2020, 7:04 PM
Abhay
Abhay - avatar
+ 6
Hey , buddy , system ("pause ") Is not supported in sololearn, so you must remove it or try same same code on some other platforms
28th May 2020, 12:26 AM
Raj Kalash Tiwari
Raj Kalash Tiwari - avatar
+ 4
This should work: #include <iostream> #include <string> int main() { int number; std::cout << "Enter a number: "; std::cin >> number; if (number > 0) { std::cout << "1"; } else if (number == 0) { std::cout << "0"; } else { std::cout << "-1"; } system("pause"); return 0; }
26th May 2020, 9:37 PM
Dennis
Dennis - avatar
+ 4
#include <iostream> #include <string> int main() { int number; cout << "Enter a number: "; cin >> number; if (number >> 0) { cout << "1"; } else if (number == 0) { cout << "0"; } else(number < 0); { cout << "-1"; } return 0; }
28th May 2020, 9:37 AM
A S Raghuvanshi
A S Raghuvanshi - avatar
+ 3
Abhay OK. For some reason I get 1-1, if I write 5 (and it should be 1.) And how can I sign the result? That everything did not mix
26th May 2020, 7:12 PM
Viktor Kizera
Viktor Kizera - avatar
+ 3
1. Remove the std:: since you're already using namespace std; 2. The else statement is not supposed to have a condition. Sin Cara M
27th May 2020, 10:08 PM
Timothy Adeleke
Timothy Adeleke - avatar
+ 2
Abhay It still doesn't work.
26th May 2020, 7:08 PM
Viktor Kizera
Viktor Kizera - avatar
+ 2
You are right ,just saw,
26th May 2020, 7:13 PM
Abhay
Abhay - avatar
+ 2
Simply remove the cout statement that's asking for user input
26th May 2020, 7:54 PM
Abhay
Abhay - avatar
+ 2
Sin Cara M depends on the IDE. Without one you could open a separate cmd instance and then run the executable that way.
27th May 2020, 6:48 AM
Dennis
Dennis - avatar
+ 2
Yea, don't open the executable directly. Open cmd.exe ( on windows ), goto the folder the executable you want to run is in and type the name of that executable in that command prompt. The program will then run and exit, but the console won't close.
27th May 2020, 6:55 AM
Dennis
Dennis - avatar
+ 2
You should use std::cout instead of std:cout, Also use std::cin for getting the input.
27th May 2020, 6:28 PM
Awais Sheikh
Awais Sheikh - avatar
+ 1
#include <iostream> #include <string> using namespace std; int main() { int number; std:cout << "Enter a number: "; std:cin >> number; if (number >> 0) { cout << "1"; } else if (number == 0) { cout << "0"; } else(number < 0); { cout << "-1"; } system("pause"); return 0; }
26th May 2020, 7:09 PM
Viktor Kizera
Viktor Kizera - avatar
+ 1
So, how can you solve this, because I no longer understand, you will also help)
26th May 2020, 7:19 PM
Viktor Kizera
Viktor Kizera - avatar
+ 1
So as I thought else don't take any condition ,it is simply else{ }
26th May 2020, 7:22 PM
Abhay
Abhay - avatar
+ 1
That is? And how can you deduce the result? That the answer was not simple, and wrote "Result" and there the answer
26th May 2020, 7:24 PM
Viktor Kizera
Viktor Kizera - avatar
+ 1
I didn't get what you mean ,but the program wasn't giving any errors ,so I looked up on search engine how if else works in c++ and found that else doesn't takes any condition statement
26th May 2020, 7:25 PM
Abhay
Abhay - avatar
+ 1
What to do, I still need the result to be displayed in the signed place
26th May 2020, 7:29 PM
Viktor Kizera
Viktor Kizera - avatar
+ 1
You mean by "signed"? Because it's displaying the result
26th May 2020, 7:30 PM
Abhay
Abhay - avatar
+ 1
mean that the result was not just numbers, but would be signed that this is the answer
26th May 2020, 7:34 PM
Viktor Kizera
Viktor Kizera - avatar