473,799 Members | 3,442 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problem With this Code...Please Help

I am writing a program that tells users to enter 2 sides of a
rectangle. From that the program will output a drwaing of the
rectangle using "*"'s... Here is my problem. Say I enter 5 and 10 for
the 2 sides.. This is what is output.

********** *
* *
* *
* *
**********

I dont know why it is adding that asterk on the first row.. Same
thing happens if I enter 2 other sides. Etc... Any help would be
appriciated!!!

Here is my code so far: I use Turbo hence the .h

#include <iostream.h>
#include <conio.h>
#include <iomanip.h>
int main()
{
clrscr();

int side1, side2;

cout<<"Please enter side 1: ";
cin>>side1;
cout<<"Please enter side 2: ";
cin>>side2;

for(int a=1; a<side1; a++)
cout<<"*";

for(int b=1; b<=(side2-1); b++)
cout<<"*"<<setw (side1-1)<<"*"<<endl;

for(int c=1; c<=side1; c++)
cout<<"*";
return 0;
}
Jul 22 '05
12 1540
1111111111 wrote:

I am writing a program that tells users to enter 2 sides of a
rectangle. From that the program will output a drwaing of the
rectangle using "*"'s... Here is my problem. Say I enter 5 and 10 for
the 2 sides.. This is what is output.


Oh, I meant to add, learn to use your debugger. Follow through the
program execution.


Brian Rodenborn
Jul 22 '05 #11
The problem is that you're not moving to the next line after the first row of *s.

If you write:
*********
Then:
* *

The result is
********** *

Just add a "cout << endl;" after the first for and replace "a<side1" by "a<=side1".

Schisto

eh***@hotmail.c om (1111111111) wrote in message news:<3f******* *************** ****@posting.go ogle.com>...
I am writing a program that tells users to enter 2 sides of a
rectangle. From that the program will output a drwaing of the
rectangle using "*"'s... Here is my problem. Say I enter 5 and 10 for
the 2 sides.. This is what is output.

********** *
* *
* *
* *
**********

I dont know why it is adding that asterk on the first row.. Same
thing happens if I enter 2 other sides. Etc... Any help would be
appriciated!!!

Here is my code so far: I use Turbo hence the .h

#include <iostream.h>
#include <conio.h>
#include <iomanip.h>
int main()
{
clrscr();

int side1, side2;

cout<<"Please enter side 1: ";
cin>>side1;
cout<<"Please enter side 2: ";
cin>>side2;

for(int a=1; a<side1; a++)
cout<<"*";

for(int b=1; b<=(side2-1); b++)
cout<<"*"<<setw (side1-1)<<"*"<<endl;

for(int c=1; c<=side1; c++)
cout<<"*";
return 0;
}

Jul 22 '05 #12
> > Get yourself a C++ compiler, e.g. mingw g++ (it's free).

No, do not use that one. A much better free one is availible from Microsoft here:
http://msdn.microsoft.com/visualc/vctoolkit2003/


This oughta be rich........... ............. ;-)
Jul 22 '05 #13

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
3764
by: Kostatus | last post by:
I have a virtual function in a base class, which is then overwritten by a function of the same name in a publically derived class. When I call the function using a pointer to the derived class (ClassB* b; b->func(); ) the base-class function is called instead of the new function in the derived class. All other similar functions (virtual in the base class and overwritten in the the derived class) work fine, it's just this one function. ...
2
1570
by: Fabrice Labrousse | last post by:
Hello, Here is a hard problem i cannot solve about window.opener method I think you'll need to be a specialist to find the solution... i can't find the solution by myself ! Please help me. Here is the problem (quiet complicated to explain). I use two differents servers with two IIS 4.0 Web servers On the first one (let's name it Server1) i got my web site. On my web site,
3
3857
by: Spacy | last post by:
Am creating a HTML Report in asp.net. To save this report to excel on client-side, i write this code: Response.ContentType = "application/vnd.ms-excel" Response.AddHeader("content-disposition", "attachment; filename=Report.xls") But once the report is saved in excel, on click of hyperlink for second html report, i dont get the second report. the same old first html report is displayed. Please can anyone help me. Am frustrated with...
5
2641
by: Henry Jordon | last post by:
ok I have my problem entering in an expression in infix notation and it outputs the postfix notation. I now need to evaluate the postfix notation. I have some code written and there are comments as to what I want to do but am unable to get it to work. So if someone could please help me it would greatly be appreciated. Thanks for your help. code: #include <cstdio> #include <cstdlib>
28
5224
by: Jon Davis | last post by:
If I have a class with a virtual method, and a child class that overrides the virtual method, and then I create an instance of the child class AS A base class... BaseClass bc = new ChildClass(); .... and then call the virtual method, why is it that the base class's method is called instead of the overridden method? How do I fix this if I don't know at runtime what the child class is? I'm using Activator.CreateInstance() to load the...
9
2826
by: Rajat Tandon | last post by:
Hello there, I am relatively new to the newsgroups and C#. I have never been disappointed with the groups and always got the prompt replies to my queries.This is yet another strange issue, I am facing. Please please help me to solve this as soon as possible. So here we go ... I am not able to take the screen shot of the windows form based "Smart
2
7152
by: almurph | last post by:
Hi everyone, Can you help me please? I am having a problem with the encryption/decryption of words with the Irish fada in them. The Irish fada is like this: áéíóú/ÁÉÍÓÚ. It's kind of like the French grave... Anyway when I run encryption on a plaintext word like:
2
1623
by: cty0000 | last post by:
Please anybody help me... I have some serious problem.. I'm doing to keep equpiment list(string).. In my code, there are 3 page which are having 4 equpiment ID (user control.) like this window FORM ==================================================================
8
1661
by: cpptutor2000 | last post by:
Could some C guru please help me? I have a function that takes as an argument a pointer to an array of unsigned chars (basically a hex representation of a dotted decimal IP address). When I print out the received values in the receiving function, I get something completely different from what I passed in. The following are the relevant code snippets: In the calling function: unsigned char* TempAddrs = {"0xC0", "0xA8", "0x00", "0x63"};
0
1977
by: Filemaxor | last post by:
I have gotten my code to be able to allow people to add new text to a .txt document and able to call up files so the user can see whats in it. The problem i'm having is getting the for loop to work correctly so that i can allow certain indexes to be removed without completely deleting everything else. This is what i have so far. Code is below It's in the e part of the code and I have //remed the location of the for loop containg the...
0
9688
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10259
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10238
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10030
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9077
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7570
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6809
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5467
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5589
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.