positive number

hi how can I 10 positive number ,and when I put 1 a negative number to stop the program?
Last edited on
Use int as your datatype. Then after every input check if the input is < 0.
#include <iostream.h>

int main (void)

{

int = 0;
int num1,num2,num3;



cout << "enter a 3 numbers:;
cin >> num;

while (num < 0)
{


}

return(0);

}

this is true?
Last edited on
Close.

Remember, you want to continue while the number is not < 0.

[code]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <iostream.h>

int main()
{
  // use an array
  int numbers[ 10 ];
  int number_of_numbers = 0;

  while (number_of_numbers < 10)
  {
    cout << "Enter a(nother) whole number, or -1 to quit: ";
    cin >> numbers[ number_of_numbers ];

    if (numbers[ number_of_numbers ] < 0) break;
    else number_of_numbers += 1;
  }

  return 0;
}
[/code]

BTW, unless you are required to use an out-of-date compiler by your professor or something, you should invest in something more modern.

An Article on compilers, IDEs, etc.
http://cplusplus.com/articles/j8hv0pDG/

Another place to find free compilers and IDEs
http://www.freebyte.com/programming/cpp/#cppcompilers
Topic archived. No new replies allowed.