Answer to Question #323321 in C++ for Christine Traya

Question #323321

write a program that calculates and prints the sum of the even integers from 2 to user defined limit and product of odd integers from 1 to user defined limit. use a do-while loop that ask the user whether the program should be terminated or not also maintain a count as to how many times the user ran to do-while loop


1
Expert's answer
2022-04-04T07:48:17-0400
#include <iostream>

using namespace std;

int main(void)
{
	int limit;
	int count;
	char c;
	double sumEven, prodOdd;
	do
	{
		cout << "Please, enter a limit: ";
		cin >> limit;
		sumEven = 0;
		prodOdd = 1;
		count = 0;
		for (int i = 0; i <= limit; i++)
		{
			if (i % 2 == 0)
				sumEven += i;
			else if (i % 2 == 1)
				prodOdd *= i;
			count++;
		}
		cout << "Sum of even is " << sumEven
			<< "\nProduct of odd is " << prodOdd
			<< "\nUser run do-while loop " << count << " times";
		cout << "\nThe program should be terminated or not? [Y/N]: ";
		cin >> c;
	} while (c=='N');	
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

shadrack kirop
16.02.23, 11:27

cool

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS