User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the C++ section within the Software Development category of DaniWeb, a massive community of 397,768 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,489 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C++ advertiser:
Views: 1982 | Replies: 12
Reply
Join Date: Dec 2004
Posts: 15
Reputation: LAMJAM is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 0
LAMJAM LAMJAM is offline Offline
Newbie Poster

Help with simple problem

  #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*
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Apr 2004
Posts: 3,462
Reputation: Dave Sinkula is a glorious beacon of light Dave Sinkula is a glorious beacon of light Dave Sinkula is a glorious beacon of light Dave Sinkula is a glorious beacon of light Dave Sinkula is a glorious beacon of light Dave Sinkula is a glorious beacon of light 
Rep Power: 16
Solved Threads: 138
Colleague
Dave Sinkula's Avatar
Dave Sinkula Dave Sinkula is offline Offline
long time no c

Re: Help with simple problem

  #2  
Dec 14th, 2004
This is assignment: This is comparison: [edit]And these are code tags: [code][/code]
Reply With Quote  
Join Date: Nov 2004
Location: Netherlands
Posts: 5,661
Reputation: jwenting is a jewel in the rough jwenting is a jewel in the rough jwenting is a jewel in the rough jwenting is a jewel in the rough 
Rep Power: 18
Solved Threads: 192
Colleague
jwenting's Avatar
jwenting jwenting is offline Offline
duckman

Re: Help with simple problem

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

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

Re: Help with simple problem

  #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  
Join Date: Apr 2004
Posts: 3,462
Reputation: Dave Sinkula is a glorious beacon of light Dave Sinkula is a glorious beacon of light Dave Sinkula is a glorious beacon of light Dave Sinkula is a glorious beacon of light Dave Sinkula is a glorious beacon of light Dave Sinkula is a glorious beacon of light 
Rep Power: 16
Solved Threads: 138
Colleague
Dave Sinkula's Avatar
Dave Sinkula Dave Sinkula is offline Offline
long time no c

Re: Help with simple problem

  #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  
Join Date: Dec 2004
Posts: 15
Reputation: LAMJAM is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 0
LAMJAM LAMJAM is offline Offline
Newbie Poster

Re: Help with simple problem

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

Re: Help with simple problem

  #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  
Join Date: Nov 2004
Location: Netherlands
Posts: 5,661
Reputation: jwenting is a jewel in the rough jwenting is a jewel in the rough jwenting is a jewel in the rough jwenting is a jewel in the rough 
Rep Power: 18
Solved Threads: 192
Colleague
jwenting's Avatar
jwenting jwenting is offline Offline
duckman

Re: Help with simple problem

  #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  
Join Date: Dec 2004
Posts: 15
Reputation: LAMJAM is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 0
LAMJAM LAMJAM is offline Offline
Newbie Poster

Re: Help with simple problem

  #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  
Join Date: Apr 2004
Posts: 3,462
Reputation: Dave Sinkula is a glorious beacon of light Dave Sinkula is a glorious beacon of light Dave Sinkula is a glorious beacon of light Dave Sinkula is a glorious beacon of light Dave Sinkula is a glorious beacon of light Dave Sinkula is a glorious beacon of light 
Rep Power: 16
Solved Threads: 138
Colleague
Dave Sinkula's Avatar
Dave Sinkula Dave Sinkula is offline Offline
long time no c

Re: Help with simple problem

  #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  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb C++ Marketplace
Thread Tools Display Modes

Similar Threads
Other Threads in the C++ Forum

All times are GMT -4. The time now is 4:20 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC