Help with simple problem

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Dec 2004
Posts: 15
Reputation: LAMJAM is an unknown quantity at this point 
Solved Threads: 0
LAMJAM LAMJAM is offline Offline
Newbie Poster

Help with simple problem

 
0
  #1
Dec 14th, 2004
Hi,
Here's my code:
#include <iostream.h>

int main ()
{
int i;

cout << "Please enter a number" << endl;
cin >> i;

if (i < 0)
{ cout << "The number you entered is negative.\n";}

if (i = 0)
{ cout << "The number you entered is zero.\n";}

if (i > 0)
{ cout << "The number you entered is positive.\n";}

else
{ cout << "Thank you for using this program.\n";}

return 0;
}


I just want to have the program print if the number is 0, negative or positive. The code works with no errors but all it does is ask for a number, and when you hit enter it says Thanks...What am I doing wrong? I've been on this for 2 hours! HELP.
*Lori*
Reply With Quote Quick reply to this message  
Join Date: Apr 2004
Posts: 4,359
Reputation: Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future 
Solved Threads: 239
Team Colleague
Dave Sinkula's Avatar
Dave Sinkula Dave Sinkula is offline Offline
long time no c

Re: Help with simple problem

 
0
  #2
Dec 14th, 2004
This is assignment:
  1. i = 1
This is comparison:
  1. i == 1
[edit]And these are code tags: [code][/code]
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 6,143
Reputation: jwenting is just really nice jwenting is just really nice jwenting is just really nice jwenting is just really nice 
Solved Threads: 212
Team Colleague
jwenting's Avatar
jwenting jwenting is offline Offline
duckman

Re: Help with simple problem

 
0
  #3
Dec 14th, 2004
what does " if (i=0) " do?

think about that, there's an error on that line
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 15
Reputation: LAMJAM is an unknown quantity at this point 
Solved Threads: 0
LAMJAM LAMJAM is offline Offline
Newbie Poster

Re: Help with simple problem

 
0
  #4
Dec 14th, 2004
Originally Posted by jwenting
what does " if (i=0) " do?

think about that, there's an error on that line
Well, I think it should go to cout << The number you entered is zero. Right??
*Lori*
Reply With Quote Quick reply to this message  
Join Date: Apr 2004
Posts: 4,359
Reputation: Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future 
Solved Threads: 239
Team Colleague
Dave Sinkula's Avatar
Dave Sinkula Dave Sinkula is offline Offline
long time no c

Re: Help with simple problem

 
0
  #5
Dec 14th, 2004
Originally Posted by LAMJAM
Well, I think it should go to cout << The number you entered is zero. Right??
Is zero true or false?
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 15
Reputation: LAMJAM is an unknown quantity at this point 
Solved Threads: 0
LAMJAM LAMJAM is offline Offline
Newbie Poster

Re: Help with simple problem

 
0
  #6
Dec 14th, 2004
Thanks! I knew it was something stupid!
*Lori*
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 15
Reputation: LAMJAM is an unknown quantity at this point 
Solved Threads: 0
LAMJAM LAMJAM is offline Offline
Newbie Poster

Re: Help with simple problem

 
0
  #7
Dec 14th, 2004
I have another one that's making me crazy. My code so far is...I just need some prodding-please.

#include <iostream.h>


void print_value
int global = x;
x = 0;


int main ()

{

int local = y;
y = num?
cin please enter num.


// function incx loop 15 times

incx = x++ //increment x by 1 each time

cout the value of x is x.
*Lori*
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 6,143
Reputation: jwenting is just really nice jwenting is just really nice jwenting is just really nice jwenting is just really nice 
Solved Threads: 212
Team Colleague
jwenting's Avatar
jwenting jwenting is offline Offline
duckman

Re: Help with simple problem

 
0
  #8
Dec 14th, 2004
you're not thinking!
What does i=0 do?
So what happens when you do if (i=0) ?
And indeed what is the result if if (i=0) ?

some hints:
assignment, false
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 15
Reputation: LAMJAM is an unknown quantity at this point 
Solved Threads: 0
LAMJAM LAMJAM is offline Offline
Newbie Poster

Re: Help with simple problem

 
0
  #9
Dec 14th, 2004
Originally Posted by jwenting
you're not thinking!
What does i=0 do?
So what happens when you do if (i=0) ?
And indeed what is the result if if (i=0) ?

some hints:
assignment, false
Thanks,
I figured that one out. I just had to change it to (i ==0) and it worked.
Now my problem is with the other code...

#include <iostream.h>


void print_value
int global = x;
x = 0;


int main ()

{

int local = y;
y = num
cin please enter num.


//function incx loop 15 times

incx = x++ //increment x by 1 each time

cout the value of x is x.
*Lori*
Reply With Quote Quick reply to this message  
Join Date: Apr 2004
Posts: 4,359
Reputation: Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future 
Solved Threads: 239
Team Colleague
Dave Sinkula's Avatar
Dave Sinkula Dave Sinkula is offline Offline
long time no c

Re: Help with simple problem

 
0
  #10
Dec 14th, 2004
Okay, that's not really your code is it? Your compiler must be screaming at you. Are you having trouble with the error messages?
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC