473,383 Members | 1,879 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

need help C++

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++///
Oct 11 '08 #1
9 1893
Tassos Souris
152 100+
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++...
Oct 11 '08 #2
boxfish
469 Expert 256MB
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.
Oct 11 '08 #3
ooh!!! dear.....
give only a little code!!!
Oct 11 '08 #4
boxfish
469 Expert 256MB
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.
Oct 11 '08 #5
is this right?

Expand|Select|Wrap|Line Numbers
  1.  void main()
  2.  {
  3.  int x;
  4.  printf ("Enter value");
  5.  scanf("%d",&x);
  6.  if(x<0)
  7.  {
  8.  printf ("Number Negative");
  9.  }
  10.  else
  11.  {
  12.  if(x>0)
  13.  {
  14.  printf ("Number Positive");
  15.  }
  16.  }
  17.  else 
  18.  printf ("Number Equal to Zero");
  19.  return 0;
  20.  }
  21.  }
Oct 11 '08 #6
boxfish
469 Expert 256MB
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,
Expand|Select|Wrap|Line Numbers
  1. if (something)
  2. {
  3.     doSomething;
  4. }
  5. else
  6. {
  7.     if (someOtherThing)
  8.     {
  9.         doSomeOtherThing;
  10.     }
  11.     else
  12.     {
  13.         doSomethingElse
  14.     }
  15. }
  16.  
will work, but just use a simple if else-if else structure like this:
Expand|Select|Wrap|Line Numbers
  1. if (something)
  2. {
  3.     doSomething;
  4. }
  5. else if (someOtherThing)
  6. {
  7.     doSomeOtherThing;
  8. }
  9. else
  10. {
  11.     doSomethingElse
  12. }
  13.  
Much cleaner, with less nested if statements.
Hope this helps.
Oct 11 '08 #7
is this right?

Expand|Select|Wrap|Line Numbers
  1.  void main()
  2.  {
  3.  int x;
  4.  printf ("Enter value");
  5.  scanf("%d",&x);
  6.  if(x<0)
  7.  {
  8.  printf ("Number Negative");
  9.  }
  10.  else
  11.  {
  12.  if(x>0)
  13.  {
  14.  printf ("Number Positive");
  15.  }
  16.  }
  17.  else 
  18.  printf ("Number Equal to Zero");
  19.  return 0;
  20.  }
  21.  }
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:
Expand|Select|Wrap|Line Numbers
  1. Code removed per Posting Guidelines
  2.  
Oct 11 '08 #8
boxfish
469 Expert 256MB
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?
Oct 11 '08 #9
sicarie
4,677 Expert Mod 4TB
curiously enough-

Please read your PM's, accessible through the PMs link under the Network tab at the top of the page.

Thanks,

sicarie
Oct 12 '08 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

0
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...
6
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?
0
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...
7
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...
8
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...
3
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...
2
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...
8
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...
11
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...
0
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 ...
1
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...
0
isladogs
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...
0
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...
0
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,...
0
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...
0
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
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...
0
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.