#include <iostream> int main() { float val, sum, incr;int ok,num; ok = 0; while
ID: 3615095 • Letter: #
Question
#include <iostream> int main() { float val, sum, incr;int ok,num; ok = 0; while (!ok) { cout << "Enter an evennumber: "; cin >> num; if (num % 2 == 2) cout << "Thenumber " << num << " is not a positive even number."<< endl; else cout << num << " is even!" <<endl << endl; } incr = 1 / num; for (val = 20.0F; val <21.0; val += incr) { cout << val; sum += val; } cout <<"The sum is " << sum << endl; return 0; }
It should looklike this
#include <iostream> int main() { float val, sum, incr;int ok,num; ok = 0; while (!ok) { cout << "Enter an evennumber: "; cin >> num; if (num % 2 == 2) cout << "Thenumber " << num << " is not a positive even number."<< endl; else cout << num << " is even!" <<endl << endl; } incr = 1 / num; for (val = 20.0F; val <21.0; val += incr) { cout << val; sum += val; } cout <<"The sum is " << sum << endl; return 0; }
It should looklike this
Explanation / Answer
// Please first run programe then rate #include <iostream.h> int main() { double val=0, sum=0,incr=0; int ok,num; ok=1; while (ok) { cout << "Enter an even number: "; cin >> num; if((num%2==1)||(num<=0)) { cout << "The number " << num << " is not apositive even number." << endl; } else { cout << num << " is even!" << endl <<endl; ok=0; } } incr=1.0/num; for (val = 20.0; val<21.1; val=val+incr) { cout<<val<<" "; sum=sum+val; } cout<<endl; cout << "The sum is " << sum << endl; return 0; }Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.