Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I need a little help with these excercises... 3.Write a complex loop condition f

ID: 3538951 • Letter: I

Question

I need a little help with these excercises...

3.Write a complex loop condition for a loop that will exit when 10 numbers have been accepted or the user has entered 0 (zero) as a number. ( loop condition must be one complex condition)


4. Write a loop that will accept numbers from a user as long as he wishes to enter numbers. Calculate the sum of all numbers that were entered and when the user exits the loop, display the sum and average of the numbers entered.


5. What is the output of this nested loop ?
i = 4;
while( i >= 1)
{
j= 1;
while (j > = 1)
{
cout << j;
j = j - 1;
}
cout << i << endl;
i = i %u2013 1;
}


6. Write a C++ if statement that assigns the character A to the variable grade if the value in the score variable is between 90 and 100, both inclusive.


7. Write a C++ switch statement to display a message based on the letter grade stored in the variable grade.
A Excellent work
Grade Display message
B Great work
C Good work
D Satisfactory work
F Try harder
Other Error


8. Write a C++ while clause that processes the loop instructions as long as the user entered value in the variable reply is either X or x.


9. Write a nested loop that will print the even numbers between 20 and 30 on a line. This same output of even numbers is to be displayed on 100 lines.


10. Write C++ code to display the values 1,4,7,10.
a) Use a While loop to do the above
b) Use a For statement to display the same output.

Explanation / Answer

3. int num;

for(int i=1;i<=10;i++)

{

cin>>num;

if(num==0)

break;

}


4. int num, sum = 0, count = 0;

while(1)

{

cout<<"Enter a number. Enter 0 to exit. ";

cin>>num;

if(num == 0)

break;

sum = sum+num;

count++;

cin>>ch;

}

cout<< "Sum = "<<sum<<" Average = "<<sum*1.0/count<<endl;


5. 14

13

12

11


6. if(score>=90 && score<=100)

{

grade = 'A';

}


7. switch(grade)

{

case 'A' : cout<<"Excellent Work"<<endl;

break;

case 'B' : cout<<"Great Work"<<endl;

break;

case 'C' : cout<<"Good Work"<<endl;

break;

case 'D' : cout<<"Satisfactory Work"<<endl;

break;

case 'F' : cout<<"Try Harder"<<endl;

break;

default : cout<<"Error"<<endl;

break;

}


8. char ch;

while(1)

{

cout<<"Enter any key. Press x/X to exit.";

cin>>ch;

if(ch=='x' || ch=='X')

break;

// loop instructions here

}


9. for(int i=0;i<100;i++)

{

for(int j=21;j<30;j++)

{

if(j%2==0)

cout<<j<<" ";

}

cout<<endl;

}


10.a) int num = 1;

while(num<=10)

{

cout<<num<<endl;

num = num+3;

}



10. b) for(int num=1;num<=10; num = num+3)

{
cout<<num<<endl;

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote