Repetation and Loop statements (while or if statement) 1. Write a program that r
ID: 3641337 • Letter: R
Question
Repetation and Loop statements (while or if statement)1. Write a program that reads a collection of positive and negative num-
bers and multiplies only the positive integers. Loop exit should occur
when three consecutive negative values are read.
Explanation / Answer
For future questions, please include the programming language you need help in. Since you have not supplied one, I will write this for you in C++. Since you did not specify if the numbers will contain decimals or not I have made it include decimals #include #include using namespace std; int main () { double total = 0; double input = 0; int counter = 0; whie(true) { cout > input; if(input >= 0) { total = total * total; counter = 0; } else if(input < 0) { if(counter == 3) { break; } counter++; } } system("PAUSE"); return EXIT_SUCCESS; } Hope this helps! Did not test code since I do not have a C++ compiler on me right now.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.