hi..!! aim a beginner....
i don't know what i gonna really to do to make code...
can you help me just a simple basic C++ code
here the Q:
Write a program that reads in two integers and outputs the message telling
whether the products of the two numbers is "positive","negative" or "zero" without actually multiplying the numbers.
///simple code basic C++///
9 1893
If only one of the operands is negative then the product is negative too.
If at least one of the operands is zero then the product is zero too.
Otherwise the product is positive...
Change the above algorithm a little and translate it to C++...
Well, if you multiply two negative numbers, you get a positive number, right? Two positive numbers also make a positive. You probably know what happens when you multiply
A negative and a positive
A positive and a negative
Zero and a positive
Zero and zero
and so on.
But start simpler. Try making a program that takes a single number as input and tells you whether it's positive, negative, or zero. If you can do that, then you have already done most of what is needed for this program. We can't write the code for you; it's your assignment.
Hope this helps.
ooh!!! dear.....
give only a little code!!!
Start with a program that prompts the user for a number, stores it in a variable, and then prints out the number. Once you have that working, use a few if statements such as
if (number == 0)
to check whether the number is greater, less than, or equal to zero, and print "Positive", "Negative", or "Zero" accordingly.
is this right? - void main()
-
{
-
int x;
-
printf ("Enter value");
-
scanf("%d",&x);
-
if(x<0)
-
{
-
printf ("Number Negative");
-
}
-
else
-
{
-
if(x>0)
-
{
-
printf ("Number Positive");
-
}
-
}
-
else
-
printf ("Number Equal to Zero");
-
return 0;
-
}
-
}
I can tell you didn't try compiling it. It's close, but it has a couple of errors. first, you have to say int main, not void main. And you have the braces on the if statements messed up a bit. Indent your code! Just put some whitespace before any code in an if statement. It may seem unnecessary, because your program will work fine without it, but not using indentaion makes your code unreadable and leads to messed-up braces. The way you're doing the if statements, -
if (something)
-
{
-
doSomething;
-
}
-
else
-
{
-
if (someOtherThing)
-
{
-
doSomeOtherThing;
-
}
-
else
-
{
-
doSomethingElse
-
}
-
}
-
will work, but just use a simple if else-if else structure like this: -
if (something)
-
{
-
doSomething;
-
}
-
else if (someOtherThing)
-
{
-
doSomeOtherThing;
-
}
-
else
-
{
-
doSomethingElse
-
}
-
Much cleaner, with less nested if statements.
Hope this helps.
is this right? - void main()
-
{
-
int x;
-
printf ("Enter value");
-
scanf("%d",&x);
-
if(x<0)
-
{
-
printf ("Number Negative");
-
}
-
else
-
{
-
if(x>0)
-
{
-
printf ("Number Positive");
-
}
-
}
-
else
-
printf ("Number Equal to Zero");
-
return 0;
-
}
-
}
I thought you wanted the sign of the product of two integers? Here you're just finding the sign of one integer.
Here's the code you want: - Code removed per Posting Guidelines
-
Here you're just finding the sign of one integer.
I suggested that (s)he do that first, and then work on two numbers. Wait a minute, are you spoonfeeding?
curiously enough-
Please read your PM's, accessible through the PMs link under the Network tab at the top of the page.
Thanks,
sicarie
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Sofia |
last post by:
My name is Sofia and I have for many years been running a personals site,
together with my partner, on a non-profit basis. The site is currently not
running due to us emigrating, but during its...
|
by: Robert Maas, see http://tinyurl.com/uh3t |
last post by:
System login message says PHP is available, so I tried this:
http://www.rawbw.com/~rem/HelloPlus/h.php
It doesn't work at all. Browser just shows the source.
What am I doing wrong?
|
by: Gregory Nans |
last post by:
hello,
i need some help to 'tree-ify' a string...
for example i have strings such as :
s = """A(here 's , B(A ) silly test) C(to show D(what kind) of stuff i
need))"""
and i need to...
|
by: Mike Kamermans |
last post by:
I hope someone can help me, because what I'm going through at the moment
trying to edit XML documents is enough to make me want to never edit XML
again.
I'm looking for an XML editor that has a...
|
by: JustSomeGuy |
last post by:
I need to write an new class derived from the list class.
This class stores data in the list to the disk if an object
that is added to the list is over 1K in size.
What methods of the std stl...
|
by: Bob.Henkel |
last post by:
I write this to tell you why we won't use postgresql even though we wish we
could at a large company. Don't get me wrong I love postgresql in many
ways and for many reasons , but fact is fact. If...
|
by: Michael R. Pierotti |
last post by:
Dim reg As New Regex("^\d{1,3}.\d{1,3}.\d{1,3}.\d{1,3}$")
Dim m As Match = reg.Match(txtIPAddress.Text)
If m.Success Then
'No need to do anything here
Else
MessageBox.Show("You need to enter a...
|
by: skumar434 |
last post by:
i need to store the data from a data base in to structure
.............the problem is like this ....suppose there is a data base
which stores the sequence no and item type etc ...but i need only...
|
by: Alan Mailer |
last post by:
A project I'm working on is going to use VB6 as a front end. The back
end is going to be pre-existing MS Access 2002 database tables which
already have records in them *but do not have any...
|
by: U S Contractors Offering Service A Non-profit |
last post by:
Brilliant technology helping those most in need Inbox
Reply
U S Contractors Offering Service A Non-profit
show details
10:37 pm (1 hour ago)
Brilliant technology helping those most in need ...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
|
by: ryjfgjl |
last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
| |