c++ - User is entering 10 numbers, find max negative value and its index/position -
user entering 10 numbers, find max negative value , index/position.
ps: must use "for". plz -_-"
this code:
#include <iostream> using namespace std; int main() { double value, maxvalue, index; cin >> value; maxvalue = value; index = 1; (int = 2; <= 10; i++) { cin >> value; if (value > maxvalue&&value<0) { maxvalue = value; index = i; } } cout << "max value = " << maxvalue << " index = " << index << endl; }
change line
if (value < maxvalue && value<0)
Comments
Post a Comment