944,123 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 2933
  • C++ RSS
You are currently viewing page 1 of this multi-page discussion thread
Dec 14th, 2004
0

Help with simple problem

Expand Post »
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.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
LAMJAM is offline Offline
15 posts
since Dec 2004
Dec 14th, 2004
0

Re: Help with simple problem

This is assignment:
C++ Syntax (Toggle Plain Text)
  1. i = 1
This is comparison:
C++ Syntax (Toggle Plain Text)
  1. i == 1
[edit]And these are code tags: [code][/code]
Team Colleague
Reputation Points: 2780
Solved Threads: 312
long time no c
Dave Sinkula is offline Offline
4,790 posts
since Apr 2004
Dec 14th, 2004
0

Re: Help with simple problem

what does " if (i=0) " do?

think about that, there's an error on that line
Team Colleague
Reputation Points: 1658
Solved Threads: 331
duckman
jwenting is offline Offline
7,719 posts
since Nov 2004
Dec 14th, 2004
0

Re: Help with simple problem

Quote 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??
Reputation Points: 10
Solved Threads: 0
Newbie Poster
LAMJAM is offline Offline
15 posts
since Dec 2004
Dec 14th, 2004
0

Re: Help with simple problem

Quote originally posted by LAMJAM ...
Well, I think it should go to cout << The number you entered is zero. Right??
Is zero true or false?
Team Colleague
Reputation Points: 2780
Solved Threads: 312
long time no c
Dave Sinkula is offline Offline
4,790 posts
since Apr 2004
Dec 14th, 2004
0

Re: Help with simple problem

Thanks! I knew it was something stupid!
Reputation Points: 10
Solved Threads: 0
Newbie Poster
LAMJAM is offline Offline
15 posts
since Dec 2004
Dec 14th, 2004
0

Re: Help with simple problem

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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
LAMJAM is offline Offline
15 posts
since Dec 2004
Dec 14th, 2004
0

Re: Help with simple problem

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
Team Colleague
Reputation Points: 1658
Solved Threads: 331
duckman
jwenting is offline Offline
7,719 posts
since Nov 2004
Dec 14th, 2004
0

Re: Help with simple problem

Quote 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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
LAMJAM is offline Offline
15 posts
since Dec 2004
Dec 14th, 2004
0

Re: Help with simple problem

Okay, that's not really your code is it? Your compiler must be screaming at you. Are you having trouble with the error messages?
Team Colleague
Reputation Points: 2780
Solved Threads: 312
long time no c
Dave Sinkula is offline Offline
4,790 posts
since Apr 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: need help for programming
Next Thread in C++ Forum Timeline: validation of some kind





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC