Write a loop that prints your name 75 times, Each instance should be followed by
ID: 667170 • Letter: W
Question
Write a loop that prints your name 75 times, Each instance should be followed by a newline. At the end, print the phrase “The loop is complete”
name = “Kevin”
Write a print statement to produce the following outputs given the variable below
pi = 3.14159
Pi to two decimal places is 3.14.
Pi with a leading 0 is 03.14159.
In what scenario would a while loop go on indefinitely.
There are a few ways this could happen, however the most popular answer will be if the programmer does not update the loop control variable.
Explanation / Answer
A loop that prints your name 75 times
for (int i = 0; i < 75; i++){
cout << "Kevin" << endl;
}
cout << "The loop is complete" << endl;
Code for Pi to two decimal places is 3.14.
#include <iostream>
using namespace std;
int main() {
float pi = 3.14159;
std::cout << std::fixed;
std::cout << std::setprecision(2);
cout << "Pi to two decimal places is " << pi << endl;
return 0;
}
Code for Pi with a leading 0 is 03.14159.
#include <iostream>
using namespace std;
int main() {
float pi = 3.14159;
cout << "Pi with a leading 0 is 0" << pi << endl;
return 0;
}
scenario where a while loop would go on indefinitely.
int i = 100;
while (i > 0){
continue;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.