Why doesn\'t this program execute all the way to the end? Isthere an easy fix? W
ID: 3608879 • Letter: W
Question
Why doesn't this program execute all the way to the end? Isthere an easy fix? Will rate lifesaver...thanks!#include <iostream> using namespace std; int main() { cout << "hello" << endl; float f = 128; float t = 1.0/255; while ( f != 0 ) { f -= t; } cout << "The End" << endl; return 0; } Why doesn't this program execute all the way to the end? Isthere an easy fix? Will rate lifesaver...thanks!
#include <iostream> using namespace std; int main() { cout << "hello" << endl; float f = 128; float t = 1.0/255; while ( f != 0 ) { f -= t; } cout << "The End" << endl; return 0; }
Explanation / Answer
please rate - thanks not every floating point number can be represented perfectly in acomputer. Often there is round off. Also your number may never be zero, it may only approach zero, and thenbe less then zero. You can check fRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.