rewrite this post and code their for loops as while loops. The only thing I need to see in the while loop body is a statement that would change the loop counter as the for loop statement would.
for (cars = 70; cars < 86; cars++)
{
}
for (planes = 75; planes >= 0; planes--)
{
}
for (trains = 0; trains < 100; trains += 4)
{
}
Part 2: I used my third for loop
do
{
trains += 4;
}
while(trains < 100);
cars = 70;
while (cars < 86)
{
cars++;
}
planes = 75;
while (planes >= 0)
{
planes--;
}
trains = 0;
for (trains < 100)
{
trains++;
}
rewrite this post and code their for loops as while loops. The only thing I need...
In C++ Programming, Try using loops only. This lab demonstrates the use of the While Loop and the Do While Loop as error checking mechanisms. You will be using each of these loops to solve the same problem. Please put them both in the same program. When you test the code, you will not see a difference in the way they execute - but there will be a difference in the logic when writing the code. You will want to...
MATLAB You've recently looked at 'while' loops in Matlab. Break statements can be contained within 'while' loops to exit the loop early. Look at the following example code: x=-10; while x<0 x=x+2; if x == -2 break; end end Without the break statement, the while loop would usually add 2 to x=-10 until x=0, and then produce a final answer of x=0 at the end of the loop. Now, the loop ends prematurely when the value of...
2. Rewrite the following loop into a while loop statement: (4 Marks) (CLO2:PLO5:C2) int i, b; cout<<"Please enter the lower bound of the loop:\n"; cin>>b; for (i = 70; b = i; i--) cout << i << endl; CSCS1511/March2019 Page 4 of 6
Need in Python! Consider the following program and expected output. Rewrite it using a for loop and a conditional break statement such that it has the same output. HINT: Stay with i as the main loop counter and let j control the break behavior. i = 0 while i < 10 and j < 10 : j = i * 2 print(i, j) i += 1 # Output below, for reference - not part of the program! 0 0 1...
Need in Python! Consider the following program and expected output. Rewrite it using a for loop and a conditional break statement such that it has the same output. HINT: Stay with i as the main loop counter and let j control the break behavior. i = 0 while i < 10 and j < 10 : j = i * 2 print(i, j) i += 1 # Output below, for reference - not part of the program! 0 0 1...
53. Rewrite the if statement below using only the relational operator < in all conditions. Assume that the value of score is between 0 and 100 inclusive. 54. Rewrite the following code segment as an equivalent segment that uses a do-while statement. 55. Assuming the following declaration: char my array[9] - ['C', 'p', 't', 'S', '9, '1', '2', '1']; What is the value of*(my array +4)?
Control Structures and Subroutines
I. A while loop whose condition is not made false is called an infi nite loop. However, it is infinite, in the sense of continuing to run forever, only in theory. The loop will stop at some point. Why? 2. To evaluate the if statements in this question below, assume that a Print statement simply prints whatever is in quotes after it. The phrases after a semicolon in the third code fragment are comments and are...
A) Rewrite the following pseudocode segment in C++ using the loop structures (for and while). Assume that all the variables are declared and initialized. k-G+ 13)/27 loop: if k> 10 then goto out k=k+1 i=3"k-1 goto loop I out: B) Rewrite the following code segment in C++ using the multiple-selection (switch and if-else) statements. Assume that all the variables are declared and initialized. if((k 1) || (k 2))j-2 k-1 if ((k 3) || ( ks))j - 3.k+1 if (k 4)j-4k-1...
Rewrite the if statement below using only the relational operator < in all conditions. Assume that the value of score is between 0 and 100 inclusive. Rewrite the following code segment as an equivalent segment that uses a do-while statement. Assuming the following declaration: char my array[9] = ['C', 'p', 't', 'S', '', '1', '2', '1'); What is the value of *(myarray, + 4)? What will be the values of k[1], k[2], and k[3] after execution of the code segment below assuming the input data shown?
Part 1: Python code; rewrite this code in C#, run the program and submit - include comments number= 4 guesscount=0 guess=int(input("Guess a number between 1 and 10: ")) while guess!=number: guesscount=guesscount+1 if guess<number: print("Your guess is too low") elif guess>number: print("Your guess is too high") else: print("You got it!!") guess=int(input("Guess again: ")) print("You figured it out in ",guesscount," guesses") Part 2: C++ code; rewrite the following code in C#. Run the program and submit. - include comments #include <iostream> using...