•
•
•
•
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
![]() |
•
•
Join Date: Dec 2004
Posts: 15
Reputation:
Rep Power: 4
Solved Threads: 0
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.
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*
•
•
Join Date: Nov 2004
Location: Netherlands
Posts: 5,661
Reputation:
Rep Power: 18
Solved Threads: 192
•
•
Join Date: Dec 2004
Posts: 15
Reputation:
Rep Power: 4
Solved Threads: 0
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.
#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*
•
•
Join Date: Nov 2004
Location: Netherlands
Posts: 5,661
Reputation:
Rep Power: 18
Solved Threads: 192
•
•
Join Date: Dec 2004
Posts: 15
Reputation:
Rep Power: 4
Solved Threads: 0
•
•
•
•
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*
![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
•
•
•
•
DaniWeb C++ Marketplace
- Installing Windows 98 On VMware. Floppy problem (Windows 9x / Me)
- Newbie - looping and array [very simple] problem (PHP)
- Help me with this Simple Problem plss (C)
- BUTTON DOES NOT WORK??? simple problem (C)
- Simple problem regardingform elements (ASP)
- Mac Mouse Problem! Help me out? (OS X)
Other Threads in the C++ Forum
- Previous Thread: need help for programming
- Next Thread: validation of some kind



Linear Mode