473,793 Members | 2,948 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

can someone fill up the following program

Hello, somehow, the rightside part of the code got cut on most of the
lines. Can someone fill up the missing code. it should work like this
http://www.compcamps.com/camps2005/n...nd/diamond.exe

#include <iostream>
#include <math.h>
using namespace std;
int main()
{
char charshow;
char again;
int i;
float lines;
int line;
char forh;
while(again!='n ')
{
cout<<"Would you like to make a filled or hollow diamond? ";
cin>>forh;
cout<<"Input character to use: ";
cin>>charshow;
cout<<"Input the number of lines to center: ";
cin>>line;
lines=line;
line=ceil(lines/2);
cout<<"I will now generate..."< system("pause") ;
if(forh=='h')
{
for(i=1;i {
//spaces
for(int l=0;l {
cout<<" ";
}
cout< for(int j=0;j {
cout << " ";
}
//spaces
if(i!=1)
{
cout< }
for(int l=0;l {
cout<<" ";
}
cout << endl;
}
for(i=lines;i>0 ;i--)
{
for(int l=0;l {
cout<<" ";
}
cout< for(int j=0;j {
cout << " ";
}
if(i!=1)
{
cout< }
for(int l=0;l {
cout<<" ";
}
cout << endl;
}
}
else{
for(i=1;i {
//spaces
for(int l=0;l {
cout<<" ";
}
cout< for(int j=0;j {
cout < }
//spaces
if(i!=1)
{
cout< }
for(int l=0;l {
cout<<" ";
}
cout << endl;
}
for(i=lines;i>0 ;i--)
{
for(int l=0;l {
cout<<" ";
}
cout< for(int j=0;j {
cout < }
for(int l=0;l {
cout<<" ";
}
cout << endl;
}
}
cout<<"Would you like to do this again? (y,n): ";
cin>>again;
}
return 0;
}

Dec 17 '06 #1
5 1651
on*******@gmail .com wrote:
Hello, somehow, the rightside part of the code got cut on most of the
lines. Can someone fill up the missing code. it should work like this
http://www.compcamps.com/camps2005/n...nd/diamond.exe
No problem:

http://www.compcamps.com/camps2005/n...nd/diamond.cpp

Dec 17 '06 #2

Colander wrote:
on*******@gmail .com wrote:
Hello, somehow, the rightside part of the code got cut on most of the
lines. Can someone fill up the missing code. it should work like this
http://www.compcamps.com/camps2005/n...nd/diamond.exe

No problem:

http://www.compcamps.com/camps2005/n...nd/diamond.cpp
wow. i didnt see that
thank you very much

Dec 17 '06 #3
On 17 Dec 2006 14:33:16 -0800 in comp.lang.c++, on*******@gmail .com
wrote,
>
Colander wrote:
>on*******@gmail .com wrote:
Hello, somehow, the rightside part of the code got cut on most of the
lines. Can someone fill up the missing code. it should work like this
http://www.compcamps.com/camps2005/n...nd/diamond.exe

No problem:

http://www.compcamps.com/camps2005/n...nd/diamond.cpp

wow. i didnt see that
thank you very much
Without grubbing through the web site, I can only guess that code was
written to serve as a horrible example.

To begin with, when you find yourself writing the same code over again
that you have already written, or the same code with minor variations,
you should experience an overwhelming desire to extract that repeated
code out into a function of its own, with the variations as parameters.
Each function should ideally be a few lines long, short enough to
understand from beginning to end as a whole, and with a single definable
purpose.
#include <iostream>
#include <string>
using namespace std;

void doline(int this_line, int size, char charshow, char fillchar)
{
cout << string(size-this_line, ' ') << charshow;
if (this_line 1)
cout << string(this_lin e*2-3, fillchar) << charshow;
cout << '\n';
}

void diamond(int size, char charshow, char fillchar)
{
for (int this_line = 1; this_line<size; this_line++)
doline(this_lin e, size, charshow, fillchar);

for (int this_line = size; this_line>0; this_line--)
doline(this_lin e, size, charshow, fillchar);
}
Dec 18 '06 #4

on*******@gmail .com wrote:
Hello, somehow, the rightside part of the code got cut on most of the
lines. Can someone fill up the missing code. it should work like this
http://www.compcamps.com/camps2005/n...nd/diamond.exe

#include <iostream>
#include <math.h>
using namespace std;
int main()
{
char charshow;
char again;
int i;
float lines;
int line;
char forh;
while(again!='n ')
{
cout<<"Would you like to make a filled or hollow diamond? ";
cin>>forh;
cout<<"Input character to use: ";
cin>>charshow;
cout<<"Input the number of lines to center: ";
cin>>line;
lines=line;
line=ceil(lines/2);
cout<<"I will now generate..."< system("pause") ;
if(forh=='h')
{
for(i=1;i {
//spaces
for(int l=0;l {
cout<<" ";
}
cout< for(int j=0;j {
cout << " ";
}
//spaces
if(i!=1)
{
cout< }
for(int l=0;l {
cout<<" ";
}
cout << endl;
}
for(i=lines;i>0 ;i--)
{
for(int l=0;l {
cout<<" ";
}
cout< for(int j=0;j {
cout << " ";
}
if(i!=1)
{
cout< }
for(int l=0;l {
cout<<" ";
}
cout << endl;
}
}
else{
for(i=1;i {
//spaces
for(int l=0;l {
cout<<" ";
}
cout< for(int j=0;j {
cout < }
//spaces
if(i!=1)
{
cout< }
for(int l=0;l {
cout<<" ";
}
cout << endl;
}
for(i=lines;i>0 ;i--)
{
for(int l=0;l {
cout<<" ";
}
cout< for(int j=0;j {
cout < }
for(int l=0;l {
cout<<" ";
}
cout << endl;
}
}
cout<<"Would you like to do this again? (y,n): ";
cin>>again;
}
return 0;
}

DO YOUR OWN HOMEWORK

Dec 18 '06 #5
Colander a écrit :
on*******@gmail .com wrote:
>Hello, somehow, the rightside part of the code got cut on most of the
lines. Can someone fill up the missing code. it should work like this
http://www.compcamps.com/camps2005/n...nd/diamond.exe

No problem:

http://www.compcamps.com/camps2005/n...nd/diamond.cpp
I fact, the code is buggy:
....
int main()
{
char charshow;
char again;
int i;
float lines;
int line;
char forh;
while(again!='n ') //'again' NOT INITIALIZED
cout<<"Would you like to make a filled or hollow
diamond? ";
cin>>forh; //SUCCESS OF READ NOT CHECKED
....

errors are mentioned only once :)

Michael
Dec 18 '06 #6

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

Similar topics

6
1988
by: Michael Lauzon | last post by:
A while back, I had a program that I was working on, while taking Java in a Web Design & Development course -- this was back in 1999 -- not having the mindset of a programmer I failed that part of the course misrably. I had to do the following program, but you can see why I failed, I only managed to write to lines of code. I am wondering if there is anyone who can write it to the following criteria, maybe even make it graphical...I am...
4
2197
by: Helene Pinol | last post by:
Dear All I have a problem to insert elements in a combination of containers. Here is the declaration of the container I would like to use: vector< set<myElement> > myContainer(vectorSize,set<myElement>()); The size of the vector is known but not yet the sizes of the different sets. Within a for loop, I build some myElements and try to insert them in the correct set with: myContainer.insert(myElement);
0
1498
by: Mike Chirico | last post by:
Hopefully this will help someone... Helpful Things to Know about MySQL Mike Chirico (mchirico@users.sourceforge.net) Last Updated: Fri Apr 16 11:47:34 EDT 2004 The latest version of this document can be found at: http://prdownloads.sourceforge.net/souptonuts/README_mysql.txt?download Format is better on the above link. I'm looking for suggestions and
4
18904
by: David | last post by:
Anyone, Does anyonee now how to use the following outline to fill a matrix with zeros and call on the first function in the following program? void fill_with_zeros(int *mat){ mat=mat1=mat2=mat3; return 0; }
17
3644
by: JC | last post by:
sorry . i got one more problem i got a string with 4 char. i want to put that in a string with 26 char. how can i fill space on the remain char.. ?? is that i need to do a while loop do fill the space for the string? please help! thanks Jack
4
4534
by: jaYPee | last post by:
I have 1 dataset called "dataset1" that contains 2 tables called "course" and "courseload". in my form i have a datagrid. the datasource of this datagrid is "dataset1" and the datamember is "courseload". here's the fields of every table in my dataset. "Course" table CourseID
2
1635
by: Brett | last post by:
I have the following code in VS Studio .NET 2005 beta: Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Me.DataAdapter1.Fill(DataSet1) End Sub Where a database connection has been made during design time and I can preview data. The above line gives a "specified method is not supported
8
4667
by: cj | last post by:
I have a 2003 program that opens a foxpro table via odbc and loads in the data into a dataset. I copied the code into a 2005 program after a long wait it fails with the error ContextSwitchDeadlock was detected The CLR has been unable to transition from COM context 0x1a3008 to COM context 0x1a3178 for 60 seconds. The thread that owns the destination context/apartment is most likely either doing a non pumping wait or processing a very...
0
5383
by: santiago8000 | last post by:
hello,i'm new to vb.net,and i'm trying to do my first program for my training...my program is about the Northwind2 database in sql server,i have a "ShowAll" button,that displays in a form the "Customers" table..i know how to do it using drag and drop datagridview,but i have to write a code by myself to fill it..that's what i wrote and when i push the button i have this error message "Fill: SelectCommand.Connection property has not been...
0
9670
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
10430
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10159
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
10000
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
9033
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
7538
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
5436
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...
2
3719
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2917
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.