output largest negative number

Hi , I was wondering how to write this program:

Input double numbers until sentinel value of 0.
Output largest negative #, if theres no negative number it would output "no negative number"

for example if the input was:

1.1 -2.2 3.3 -4.4 5.5 -6.6 0
Output: -2.2

Input: 1.1 2.2 3.3 0
Output: "no negative number"
use a loop and an if statement?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include <iostream>
using namespace std;

int main()
{
    double number;
    double largest = 0;
    double negative = 0;

    cout<<"Enter numbers and 0 to stop"<<endl;
    cin>>number;

    while(number != 0)
    {
        if(number < 0)
        {
            negative = number;
            if(largest == 0)
                largest = negative;
            else
                if(negative > largest)
                    largest = negative;
        }
        cin>>number;
    }
    if(largest != 0)
        cout<<largest;
    else
        cout<<"no getaive number"<<endl;
}
As giblit has said, it's as simple as that.
Topic archived. No new replies allowed.