can someone fill up the following program

O

one.1more

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/nmagnus/c++/diamond/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;
}
 
D

David Harmon


wow. i didnt see that
thank you very much[/QUOTE]

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);
}
 
S

Signal9

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/nmagnus/c++/diamond/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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top