| | |
Help with simple problem
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Dec 2004
Posts: 15
Reputation:
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*
This is assignment: This is comparison: [edit]And these are code tags: [code][/code]
C++ Syntax (Toggle Plain Text)
i = 1
C++ Syntax (Toggle Plain Text)
i == 1
•
•
Join Date: Dec 2004
Posts: 15
Reputation:
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: Dec 2004
Posts: 15
Reputation:
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
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*
![]() |
Similar Threads
- Simple C++ Class problem (C++)
- e.cancel simple problem?? (VB.NET)
- Simple problem (Java)
- Installing Windows 98 On VMware. Floppy problem (Windows 95 / 98 / 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
| Thread Tools | Search this Thread |
api array arrays based beginner binary bitmap c++ c/c++ calculator char char* class code coding compile compiler console conversion count data database delete deploy developer dll download dynamiccharacterarray email encryption error file forms fstream function functions game getline givemetehcodez graph gui homeworkhelp homeworkhelper iamthwee ifstream input int integer java lib linker list loop looping loops map math matrix memory multiple news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference rpg sorting string strings struct temperature template text text-file tree url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






