d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > C++ Programming Help > Homework Due Today By 6
Add Reply New Topic New Poll
Member
Posts: 15,283
Joined: Oct 20 2005
Gold: 11,771.00
Trader: Trusted
Feb 4 2015 08:09am
I have been out of class for a few days due to being sick. I have caught up for the most part, but am having problems.

Here is the example in class:

Code
#include<iostream>

using namespace std;

int main()
{
for(int vert = 0; vert < 10; vert++)
{
for(int horz = 0; horz < 10; horz++)
{
cout << "*";
}

cout << endl;
}

cin.get();
return 0;

}


It comes out like this:

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

a 10x10 asterisk box.

I need to write a program for this:

.....*
....**
...***
..****
.*****
..****
...***
....**
.....*

It must have the option "Enter a number to be used".

I can't figure it out for the life of me. A diamond shape using the * as the marker. Ignore the periods

Thanks!!!

This post was edited by Coronaking on Feb 4 2015 08:33am
Member
Posts: 62,215
Joined: Jun 3 2007
Gold: 9,039.20
Feb 4 2015 08:52am
Toy language example

Code
#!/usr/bin/python3

width = 20

c = 1
while c < width*2:
print(" " * (width-c) + "* " * c) if c < width else print(" " * (c-width) + "* " * (2*width-c))
c += 1


Code

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

Member
Posts: 2,769
Joined: Dec 24 2009
Gold: 14.00
Feb 9 2015 11:35pm
Code
#include <iostream>

int main()
{
std::cout << "Enter number: " << std::endl;
int x;
std::cin >> x;

for (int i = 0; i < x; i++){
if (i < (x+1)/2){
for (int j = 0; j < (x + 1)/2-i-1; j++){
std::cout << " ";
}
for (int k = 0; k < (i + 1)*2 - 1; k++){
std::cout << "*";
}
} else {
for (int l = 0; l < i - x/2; l++){
std::cout << " ";
}
for (int m = 0; m < (x - i) + (x-1-i); m++){
std::cout << "*";
}
}
std::cout << std::endl;
}
}


Sorry answered too late, but was just curious if that's an acceptable program ^
Go Back To Programming & Development Topic List
Add Reply New Topic New Poll