Revise the program so that it accepts floating-point input and prints a floating
ID: 3691188 • Letter: R
Question
Revise the program so that it accepts floating-point input and prints a floating-point result. Make sure that you notate the constants correctly. Exercise 3.1.2. Can you revise the example so that it uses a while loop, but does not use either the do or break keyword? Note that the result should produce exactly the same behavior under all conditions that Example 3.1 does. Introducing Random Numbers _ In the next section, we're going to use a do-while loop in another game program. To keep it interesting, we need a way to generate random numbers. That's often true of games and simulations.Explanation / Answer
Exercise 3.1.1:
float n, sum = 0;
while(true)
{
cin>> n;
n += sum;
if(n <= 0.0)
break;
}
Here is the code which produces the same result, without using either do, or break statement:
char s[50];
float n, sum = 0;
while((n = atof(gets(s))) > 0.0)
sum += n;
cout<<sum<<endl;
Related 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.