473,386 Members | 1,828 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

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 1638
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_line*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_line, size, charshow, fillchar);

for (int this_line = size; this_line>0; this_line--)
doline(this_line, 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
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...
4
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> >...
0
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...
4
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){...
17
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...
4
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...
2
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) ...
8
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 ...
0
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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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,...

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.