Student Portfolio >> Index >> Coding >> Exercise 13
// Request input of 15 values and display the sum of all negative values
#include <iostream.h>
int main()
{
int i;
float inval=0, sumnegval=0;
for (i=1; i<=15; i=i+1)
{
cout << "Please enter a number: ";
cin >> inval;
{
if ( inval < 0 )
sumnegval = sumnegval + inval;
}
}
cout << "\nThe total of all negative numbers entered = " << sumnegval << endl;
return 0;
}
<< Back Forward >> |
Copyright 2005 Kerstin Kegel