Question

In: Computer Science

This is for C++ You must use either a FOR, WHILE, or DO-WHILE loop in your...

This is for C++

You must use either a FOR, WHILE, or DO-WHILE loop in your solution for this problem. Write a quick main console program to output the following checker pattern to the console:

#_#_#_#_#
_#_#_#_#_
#_#_#_#_#
_#_#_#_#_
#_#_#_#_#

Solutions

Expert Solution

Code Screenshot :

Executable Code:

#include <iostream>
using namespace std;

int main()
{
   //Declaring required variables
   int i, j;
   string b, w, t;
   //Declaring the strings
   b = "#";
   w = "_";
   //Required For loop
   for (i = 1; i <= 5; i++)
   {
       for (j = 1; j <= 9; j++)
       {
           if (j % 2 != 0)
           {
               //Printing the pattern
               cout << b;
               if (j < 10)
               {
                   cout << "";
               }
           }
           else if (j % 2 == 0)
           {
               cout << w;
               if (j < 10)
               {
                   cout << "";
               }
           }
       }
       t = b;
       b = w;
       w = t;
       cout << endl;
   }
}

Sample Output :

Please comment below if you have any queries.
Please do give a thumbs up if you liked the answer thanks :)


Related Solutions

C language and it has to be a while loop or a for loop. Use simple...
C language and it has to be a while loop or a for loop. Use simple short comments to walk through your code. Use indentations to make your code visibly clear and easy to follow. Make the output display of your program visually appealing. There is 10 points deduction for not following proper submission structure. An integer n is divisible by 9 if the sum of its digits is divisible by 9. Develop a program that: Would read an input...
Re-write following while loop into Java statements that use a Do-while loop. Your final code should...
Re-write following while loop into Java statements that use a Do-while loop. Your final code should result in the same output as the original code below. int total = 0; while(total<100) { System.out.println("you can still buy for"+(100-total)+"Dollars"); total=total+5; }
Modify the previous program to use the Do-While Loop instead of the While Loop. This version...
Modify the previous program to use the Do-While Loop instead of the While Loop. This version of the program will ask the user if they wish to enter another name and accept a Y or N answer. Remove the "exit" requirement from before. Output: Enter the full name of a person that can serve as a reference: [user types: Bob Smith] Bob Smith is reference #1 Would you like to enter another name (Y or N)? [user types: y] Enter...
Do the following lab by while or Do-while loop. question: Write a c++ program that asks...
Do the following lab by while or Do-while loop. question: Write a c++ program that asks students to enter 3 valid grades and then calculate the average and print it. if the user enters the invalid grade you should print the error message and get the new grade. Hint1: each time your program ask the following question: "Do you want to calculate another average?" and if the answer to this question is "Y" or "y" then you should continue. Hint2:...
Problem: Construct a C program that will make use of user-defined functions, the do/while loop, the...
Problem: Construct a C program that will make use of user-defined functions, the do/while loop, the for loop, and selection. Using a do/while loop, your program will ask/prompt the user to enter in a positive value representing the number of values they wish to have processed by the program or a value to quit/exit. If the user enters a 0 or a negative number the program should exit with a message to the user indicating they chose to exit. If...
ASAP PLEASE!!!! USING JAVA /* 1. When should you use a do-while loop? ** Write your...
ASAP PLEASE!!!! USING JAVA /* 1. When should you use a do-while loop? ** Write your answer as a multi-line Java comment ** */ /* 2. Identify the algorithm that matches this code snippet. Your choices are:   sum and average, counting matches, first match, prompt until match, and   comparing adjacent values.  Write your answer below the coded.        int firstNum = 0;   int number = scnr.nextInt();   while (scnr.hasNextInt())   {   int input = scnr.nextInt();   if (input == number)   {   firstNum++;   }   }...
8.40 Lab 8e: BankBalance Introduction For this lab, you will use a do-while loop to complete...
8.40 Lab 8e: BankBalance Introduction For this lab, you will use a do-while loop to complete the task. A do-while loop has this basic structure: /* variable initializations */ do{ /* statements to be performed multiple times */ /* make sure the variable that the stop condition relies on is changed inside the loop. */ } while (/*stop condition*/); Despite the structure of the do-while loop being different than that of a for loop and a while loop, the concept...
Write a program in C++ coding that utilizes a DO-WHILE loop to redisplay a menu to...
Write a program in C++ coding that utilizes a DO-WHILE loop to redisplay a menu to the user. Ask the user to input their favorite SuperHero and display a positive or funny comment about the chosen SuperHero. If RBG is chosen, display "You can't spell TRUTH without RUTH." Utilize a Do-While Loop to redisplay the menu to the user after item 1, 2 or 3 is executed. If item 4 is chosen, end the program. If the user chooses 4,...
C programming. Explain by taking a programming example how do while loop is different from while...
C programming. Explain by taking a programming example how do while loop is different from while loop?
write an operational semantic for a while loop in c++
write an operational semantic for a while loop in c++
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT