You are here:

C++/using a nested loop in dev c++

Advertisement


Question
Your task is to display on screen the 'N' symbol given two data: the length and the character symbol to use to draw the symbol. If the input of the user is less than 3, print "Erros: Length must be greater than 2" and ask again the user to input a valid length.

This program repeats unless the user types -1.

Sample Run:
Enter length and character: 5 0
00000
00000
00000
00000
00000

Answer
Sorry i could not respond to you earlier. Here is the code you need:
#include<iostream>
using namespace::std;
int main(void)
{
  int in;
  char symbol;
  cin>>in;
  do
  {
       cin>>symbol;
     while(in<3)
     {
        cout<<"Error: Length must be greater than 2"<<endl;
        cin>>in>>symbol;
     }
     for(int j=0; j<in; j++)
     {
        for(int i=0; i<in; i++)
         cout<<symbol;
        cout<<endl;
     }
       cin>>in;
  }while(in!=-1);
  return 0;
}

C++

All Answers


Answers by Expert:


Ask Experts

Volunteer


Tehreem

Expertise

I can answer questions related to C++ coding and programming techniques.

Experience

I am a C++ programmer.

Organizations
University of Engineering & Technology Lahore

Publications
http://recurseit.blogspot.com

Education/Credentials
I am doing BSCS.

©2016 About.com. All rights reserved.