+ 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((
37 Answers
+ 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
+ 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
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
+ 1
You mean by "signed"? Because it's displaying the result
+ 1
mean that the result was not just numbers, but would be signed that this is the answer