user3840416
user3840416

Reputation: 11

ASCII character rectangular box

I am kind of new to c++. so I've been asked to do a rectangular box using ASCII code using function, the characters must be 202,203, 204,216,217,221, I've tried searching and editing so I came up with this code

#include <iostream>
using namespace std;

int rectangular (int i)
{

cout << char(203);
for(int i=0; i<=40;i++);
cout << char(203);
cout << char(203)<<endl;
cout<< char (221);
for(int i=0;i<1;i++)cout<<' ';
cout<<char (221);
cout<<endl<<char (204);
for(int i=0; i<10;i++);
cout<<char (216);
cout<<char (217);

 return 0;
}

int main() 

{
    int n,i;
    rectangular(n); 
}

Managed to be executed but the result is horrific, too small 0.0

I am terribly sorry for asking such question but most of codes I found online use char (201) and now I have to make the code just as good as expected output by using these unique characters.

Is there any way to extend the horizontal line atleast?

Thank you for your help.

Upvotes: 1

Views: 4720

Answers (2)

Some programmer dude
Some programmer dude

Reputation: 409364

Loops execute a statement, that statement is, in your case, an empty statement terminated by the semicolon after the loop.

You loop looks like this:

for(int i=0; i<=40;i++);

If I reformat it a little, the loop is like this

for(int i=0; i<=40;i++)
    ; // <- empty statement

So the loop iterates 41 times, doing nothing.

Upvotes: 1

John3136
John3136

Reputation: 29266

Take the semi colons off your loops

for(int i=0; i<=40;i++);

should be

for(int i=0; i<=40;i++)

Upvotes: 2

Related Questions