473,394 Members | 1,887 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,394 software developers and data experts.

Very new, embarrassed to even ask you people..here goes

I'd be embarrassed to tell anyone how long it took me to get this far, since about 8pm last night! I have been assigned some homework to code a program that produces output in a diamond shape on screen with one user input, how many lines. I managed the triangle, centered triangle but the diamond's logic is very difficult, for me. Second term student at DeVry, six weeks since 'Hello World'. Anyone point me in the right direction>? Joe...here's what I've come up with so far, the upper half of diamond compiled, and one of this weeks three assignments. Thanks

#include <iostream>

using namespace std;

int main()
{
//variables
int dots = 0;

//process
cout << "Centered triangle program" << endl << endl;
cout << "Enter number of lines you would like in triangle up to 40: ";
cin >> dots;
cout << endl;

//for loop providing initial argument
for (int dot = 1; dot <= dots; dot = dot + 1)
{
//nested loop
for (int skip = 0; skip <= (dots-dot); skip = skip + 1)
{
cout << " ";
}
//nested loop
for (int asterick = 0; asterick < (dot*2)-1; asterick = asterick + 1)
{
// output
cout << "*";
}
//end line
cout << endl;
}
system ("pause");
return 0;
}

I've been reading a lot of the threads and am not sure I know enough to even be posting here.
Apr 21 '07 #1
2 1372
JosAH
11,448 Expert 8TB
Some observations:

- A real neat diamond needs an odd number of lines; some examples:
Expand|Select|Wrap|Line Numbers
  1.           *
  2.     *    ***
  3. *  ***  *****
  4.     *    ***
  5.           *
- The widest line in the middle contains as many stars as there are lines in the
diamond. Lets call this number 'n'.

- For the upper half of the diamond line i+1 contains two stars more than line i.

- For the lower half of the diamond line i+1 contains two stars less than line i.

- if a line contains i stars and the maximum number of stars of the diamond
equals 'n', then first you have to print (n-i)/2 spaces first on the line.

- the top half of the diamond contains lines with 1, 3, 5, 7, ... n stars

- the bottom half of the diamond contains n-2, ... 7, 5, 3, 1 stars.

Enough hints?

kind regards,

Jos
Apr 21 '07 #2
Hello Jos, very much so enough hints. Thank you for helping, now I can start over on the bottom half of my diamond as I was approaching this somewhat differently in attempting to invert the upper half. Much thanks Jos, Joe
Apr 22 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Jesper Denmark | last post by:
Within the following construction switch (expression) { int i; i = GetArgs() //return 2 case constant-expression:
1
by: jessebasketball | last post by:
i am a very beginner programmer and am stuck on a very simple problem. I am trying to make a game where the user is presented with a scenerio and options. ie you are standing in the parking lot...
21
by: Steve | last post by:
Hi, I have a form containing a lot of various forms objects (about 120-150). It takes about 10 minutes for the solution to load (only one project). If I modify the corresponding .h file and...
9
by: Vito DeCarlo | last post by:
I've been having this problem for a few weeks. PLEASE read this post before responding with some simple reason that has nothing to do with my problem. If you need more information, please request...
2
by: dave | last post by:
Hi, I have searched for the answer for this error message without success. I have seen the question many times though:) I create an ASP.NET project (VS 2005, C#), and use a very simple .mdf...
52
by: robert | last post by:
I'm very pleased to announce that Foundations of F#, the first book to be published on the F# programming, will finish its first printing run, tomorrow, Friday 25th May. It should reach any...
112
by: Prisoner at War | last post by:
Friends, your opinions and advice, please: I have a very simple JavaScript image-swap which works on my end but when uploaded to my host at http://buildit.sitesell.com/sunnyside.html does not...
1
by: =?Utf-8?B?TU5C?= | last post by:
Hi there! We are near the ending stage of an ASP.NET + IIS project, and started doing stress testing on the servers. We find ourselves with a very strange behavior, that can’t figure out since...
126
by: jacob navia | last post by:
Buffer overflows are a fact of life, and, more specifically, a fact of C. All is not lost however. In the book "Value Range Analysis of C programs" Axel Simon tries to establish a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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
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...
0
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...
0
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...

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.