Answer to Question #215660 in C++ for Ziwe

Question #215660
int i = 1;
double weight;
do
{
cout<< "Enter weight ";
cin>> weight;
cin<<endl;
weight = weight + 1;
i = i +1;
}
while (i<=5)
At which value of i will the loop condition be tested for the second time?
1
Expert's answer
2021-07-11T14:40:21-0400
//At which value of i will the loop condition be tested for the second time?
main(void)
{
	int i = 1;
	double weight;
	do
	{
		cout<< "Enter weight ";
		cin>> weight;
		cin<<endl;
		weight = weight + 1;
		i = i +1;
	}
	while (i<=5)
}


/*
	Solution: 	When the loop run first time with i = 1, i becomes 2 as (i = i+1 = 2).
				The value of i = 2 is tested first time.
				Now, the loop runs with i = 2, and i becomes 3 as (i = i+1 = 3) 
				Therefore, now i=3 is tested in second run for i=3.
*/

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

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS