Write the program). Do not know how to make. | SoloLearn: Learn to code for FREE!

+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((

c++

5/26/2020 6:48:18 PM

Sin Cara M

38 Answers

New Answer

+7

Look at std:cout ,it should be std:: cout and you aren't asking for any user input ? std::cin>>number;

+6

Hey , buddy , system ("pause ") Is not supported in sololearn, so you must remove it or try same same code on some other platforms

+6

Abdullah07-01 as you want to verify your account you have to do it by verifying your account's e- mail address

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

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

+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

+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

+2

Abhay It still doesn't work.

+2

You are right ,just saw,

+2

Simply remove the cout statement that's asking for user input

+2

Please don't use system("pause") as it's not portable and it's dangerous. See the article "Why system() is evil" https://www.cplusplus.com/forum/articles/11153/ A program should not block execution like that. I know all the unfortunate Indian programmers have been taught using the Turbo C function getch() to block program termination is the epitome of debugging strategies but in the real world it's regarded as a lazy hack. It displays a lack of knowledge of how to use a debugger and a lack of understanding of console mode programming.

+2

Sin Cara M depends on the IDE. Without one you could open a separate cmd instance and then run the executable that way.

+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.

+2

You should use std::cout instead of std:cout, Also use std::cin for getting the input.

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

+1

So, how can you solve this, because I no longer understand, you will also help)

+1

So as I thought else don't take any condition ,it is simply else{ }

+1

That is? And how can you deduce the result? That the answer was not simple, and wrote "Result" and there the answer

+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

+1

What to do, I still need the result to be displayed in the signed place