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.

Edited 3 Years Ago by happygeek: fixed formatting

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??

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.

Edited 3 Years Ago by happygeek: fixed formatting

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.

Edited 3 Years Ago by happygeek: fixed formatting

Okay, that's not really your code is it? Your compiler must be screaming at you. Are you having trouble with the error messages?

That's what I have so far. I can't figure it out. And this is my first exposure to C++.

I'm supposed to:
declare global int variable within main named x initialized to 0
declare a local int variable in main named y
prompt user for value of y in main
add loop that calls function incx y number of times
include function incx to increment value of x by one
and print the value of x after each loop

I'm lost!!

declare global int variable within main named x initialized to 0

int x = 0;


declare a local int variable in main named y

int main()
{

int y;
return 0;
}

prompt user for value of y in main

You did a prompt in your first post. It was the cout/cin combo.

add loop that calls function incx y number of times

You'll need a function incx() prototyped or defined before you call it. The function definition will look a lot like main. You'll likely want to use a for loop from 0 to y.

for ( int i = 0; i < y; ++i )
{
/* loop body */
}

include function incx to increment value of x by one

Something to put in the loop body.

and print the value of x after each loop

Something to put in the loop body.

That ought to be enough for you to take another spin at it. And please post your next code attempt within code tags: [code][/code].

Edited 3 Years Ago by Dani: Fixed formatting

#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;
}

Edited 3 Years Ago by happygeek: fixed formatting

This article has been dead for over six months. Start a new discussion instead.