C++ :: Star Pyramid Program - Adding Stars?

Sep 13, 2013

I have written a star pyramid program, it adds two stars at a time but I want to rewrite the program so the stars double each time.

#include<iostream>
using namespace std;
int main() {
int a = 0, b = 8;
for (int c = 1; c < 10; c++) {
for (int space = b; space > 0; space--)

[Code] ...

View 1 Replies


ADVERTISEMENT

C++ :: Pyramid Of Stars With Spaces

Mar 21, 2013

How to solve this (for cycle)?

View 12 Replies View Related

C# :: Upper Pyramid Is Working Fine But Lower Pyramid Executes Infinite

Feb 10, 2015

I need to print like below pattern.

1
121
12321
1234321
123454321
1234321
12321
121
1

I got the upper pattern but below pattern is not working it executes infinte loop, how to reslove this.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ro {
class ro {
static void Main(string[] args) {
int numberoflayer = 5, Space, Number;

[Code] ....

View 1 Replies View Related

C/C++ :: Program To Print Irregular Star Pattern?

Oct 5, 2014

I am trying to write a program that will make a pattern of stars. The last line is really tripping me up. I have to make the code only using the printf("*"); printf(" "); printf("/n"); statements once. I want to accomplish this with a for loops and if statements.

It is supposed to look like this:

* - 5 spaces before *
* * - 4 spaces before *
* * * - 3 spaces before *
* * * * * * - 0 spaces before *

This is what I've tried so far:

main()
{
int i, j, k;
i=1;
j=1;

[Code]....

here are the links on codepad [URL]

I think my first approach is way off. But I think I am on to something in the second link. I'm trying to print the "*" and extra 2 times on the fourth line. In the second link the compiler appears to be ignoring the || operator. Is my syntax incorrect in the second attempt? How should I change my if statement to make this pattern work?

View 2 Replies View Related

C++ :: Program To Display N Depth Pyramid

Feb 21, 2013

Write a program that displays n depth * pyramid.

For example,Input: 4
Output:
*
***
*****
*******

This is what i have so far but it not giving me what i want.

#include <iostream>
using namespace std;
int main() {
int star;
int count=1;
cout<<"Enter the number: ";
cin>>star;

[Code] ....

View 1 Replies View Related

Visual C++ :: Custom Pyramid Drawing Program

Jul 6, 2014

I am trying to figure out how to create a program that will draw a triangle using *'s with a base the has a user-inputted number of *'s like so:

*
***
*****

It needs to take a user inputted number and draw a pyramid like the above pyramid with the number of *'s in the base matching the user inputted number (i.e., user enters 10, so the triangle has 10 *'s in the base). I figured it would be best to first create a loop to draw out the correct number of *'s before trying to create another loop to draw out the correct number of spaces, to properly align the *'s into a triangle shape.

int width = 0;
int height = 0;
int i = 0;
int leafWidth = 0;

[Code] .....

View 7 Replies View Related

C++ :: Construct A Program Without Main Function That Output Stars

Nov 5, 2013

I am trying to construct a program without a main function that outputs stars but at the same time outputs the number and a colon after the number but before the number of star. This is the coding i have so far.

void output_stars(int num){
if (num > 0){
cout << "*";
output_stars(num-1)

[Code] ....

The program is working the way it should i just can't figure out how to output the number and a colon. The main function is written as such:

output_stars(1);
output_stars(2);
output_stars(5);
output_stars(3);
output_stars(4);
output_stars(7);

How to get the numbers of the main function to show up with the stars of the previous function.

View 6 Replies View Related

C :: Draw Magen David Star

Apr 18, 2014

problem to draw magen david star ,i find code that draw pyramid of starts. how can i modify this code to receive magen david star ?

Code:
#include <stdio.h>
int main() {
int rows, star, spaces;
char bukva='A';
int number_of_stars = 6;
int number_of_rows = number_of_stars;

[Code]....

View 4 Replies View Related

C :: Print The Star Equilateral Triangle

Dec 23, 2014

I use photos to express it. The answer is:

Code:
int main(int argc, char *argv[], int n) {
int i,j;
for (i=1;i<=n/2+1;i++) {

[Code]....

View 3 Replies View Related

C# :: How To Fix Space For Output Of Star Triangle

Mar 7, 2015

When i set any 3 inputs length, the space should be move in right position. I try to fix the space move forward into 1 space, but don't know why it doesn't work. Specially, when the number is 4 or 5. The space didn't move 1 space.

using System;
class length{
static void Main(){
int i,j,k;
string star = "*";
string s1 ="";
string s2;
int[] nums = new int[] {3,4,5};

[Code] .....

View 2 Replies View Related

C# :: Find Closest Star To The Earth

Apr 19, 2015

Consider a coordinate system for the Milky Way, in which the Earth is at (0; 0; 0). Model stars as points, and assume distances are in light years. The Milky Way consists of approximately 1012 stars, and their coordinates are stored in a file in comma-separated values (CSV) format one line per star and four fields per line, the first corresponding to an ID, and then three floating point numbers corresponding to the star location. How would you compute the k stars which are closest to the Earth? You have only a few megabytes of RAM.

View 1 Replies View Related

C++ :: Displaying Inverted Pyramid

Oct 7, 2013

The user will enter the number of '*'s on the 1st row (ntop) and then the number of rows forming the trapezoid (nrows). (using <iostream>, cout)

For instance, an inverted trapezoid with 7 '*"s in the 1st row and 3 rows forming the inverted trapezoid looks like:

for (i = nrows; i >= 1; i--) {
for (j = 0; j >= nrows; j++) {
cout << " ";
} for (k=ntop; k >= 2; k--) {
cout << "*";
} }

The output is just blank as of now.

View 3 Replies View Related

C++ :: How To Make Inverted Pyramid

Oct 4, 2013

I am new to C++ and I want to make an inverted pyramid so it follows the form of:

54321
x432x
xx3xx

or:

7654321
x65432x
xx543xx
xxx4xxx

The goal is to make it look like that pattern. The x's denote spaces. This is only for integers under 10.

#include<iostream>
using namespace std;
int main() {
int n,i,j;
cout << "Enter a positive odd number: ";
cin >> n;

[Code] ....

I am not sure how to add the spaces or make it subtract like the pattern.

View 7 Replies View Related

C/C++ :: ASCII Art For Different Triangles And Pyramid

Mar 15, 2015

I have to Write a program to produce that makes four triangles and a pyramid. I have to ask the user they height of the triangle and prevent the user from entering a height any larger than 25. It should look like this.

Enter the height of your triangle/pyramid: 3

***
**
*

*
**
***

*
**
***

***
**
*

*
***
*****

im having tourble with 3 and 4th and also pyramid.

HERES WHAT I HAVE SO FAR.

#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
int main () {
int input = 0;
cout << "Please enter the height of your triangle/pyramid: ";

[Code] .....

View 2 Replies View Related

C# :: Logic For Building Numbers Pyramid?

Jan 7, 2012

Code:
1
121
12321
1234321
123454321 EDIT:
the above pyramid looks like a doom.i.e 1-5 will be in center.1-4(L)1-3(L)1-2(L)1(L) similarly 1-4(R) 1-3(R) 1-2(R) 1(R)

I'm partly successful in building the requirement of the program.but cant able to think the logic for the other half. how can i proceed.below is the code written in c#.

Code:
for (int i = 1; i <= 5; i++)
{
//int l = 1;

[Code]....

View 3 Replies View Related

C :: Loop Statement To Print Numbers From 1 To 10 In Reverse Order Separated By Star

Apr 21, 2013

Write a for loop statement to print the numbers from 1 to 10 in reverse order separated by star :

10*9*8*7*6*5*4*3*2*1

i try to do it but it show me like this :

10*9*8*7*6*5*4*3*2*1*

how do i write to show me like the first one ?

View 10 Replies View Related

C++ :: Input Number And Print Out Same With Stars In Between

Apr 16, 2013

Basically i want to input a number for example 123456 and get back how many 7's are in the input number and also to print out that same number with stars in between like this *1*2*3*4*5*6*. Here is what i have so far:

#include <iostream>
using namespace std;
int countSeven(int x){
if(x == 7)return 1;
int c = 0;
while(x/10 > 9)c++;
return countSeven(x/10)+1;

when i compile it does not do what i tell it it just tells me there are 0 7's in the input number no matter how many there really are...

View 9 Replies View Related

C++ :: Print Stars Function In 1D Array?

May 2, 2014

I'm having trouble with my for loop near the end of the program was able to print everything else.

Sample Output:

*** end of 27610_Arrays04.cpp program ***

City City Points
--------------- 1---5----10---15---20
Belvidere **********
Freeport ********
Byron ************
Stillman Valley ***************
Rockford *********

*** end of 27610_Arrays04.cpp program ***

Input:

TODO #1: complete the coding of the points array
An integer array of 5 numbers: 10, 8, 12, 15, 9

TODO #2: complete the coding of the cities string array
An string of 5 city names intialized to:
"Belvidere", "Freeport", "Byron", "Stillman Valley", "Rockford"

Compile-time arrays with initialization lists.

Processing & Output:

TODO #3: complete the coding of the call to the printStars() function

TODO #4: code the printStars() function

#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
int main(void) {
/* declarations ------------------------------------------------*/

[Code] ....

View 2 Replies View Related

C++ :: Print Out Square Of Stars With Different Length And Width Given?

Feb 27, 2013

#include <iostream>
using namespace std;
int main()
{

[Code].....

how do i change this code to accept two numbers from the user and print it as the different length and widtth? it has to be a for loop as well.[code]

View 5 Replies View Related

C++ ::  Vertical Histogram - Variables In For Loop To Print Stars

Dec 6, 2013

I want to create a vertical histogram in my code. I already made it go vertical but not the way I want it.

Example:
I want it like this:

Range1 Range2 Range3 Range4

And asterisks under each one, depending on the user input. (My code is below and doing it on here doesn't make it come out correctly)

But what I've managed to do is this:

Range1
*
*
*

Range2
*
*

Range3
*
*
*
*

Range4
*
*

Which I don't want. I want everything else to stay pretty much the same since I can only use some features such as Arrays and really basic functions.

Here is my code: (Worked fine last time I used it and I am doing it on Visual Studio 2010 (at uni) and 2013 (on my laptop)).

#include <iostream> //Start of code
using namespace std;
int MarkValueInput; //Mark entered by user
//Counter variables for ranges in While Loop
int counterlow; //Counter for low range
int countermidlow; //Counter for mid-low range
int countermidhigh; //Counter for mid-high range
int counterhigh; //Counter for high range

[Code] .....

View 4 Replies View Related

C++ :: Print Stars Function - Corresponding To Array Index Size

Nov 24, 2014

I am having trouble getting the stars to output correctly in the printStars function. the final output should look something like this:

#include <iostream>
using namespace std;
int readArray(int input[], int size);
void printArray(int input[], int count);
void printStars(int input[], int size);

[Code] ...

View 3 Replies View Related

C++ :: Program Not Adding Up Totals

Mar 5, 2014

'm new to programing and I'm trying to get this program to add up a price of coffee to the add on extras such as cinnamon, etc. But once the program runs it doesn't add up the coffee price with the extras and I've been at it for hours...

Code:

#include <iostream>
#include <cstdlib>
using namespace std;
int main()

[Code] ......

View 6 Replies View Related

C :: Adding A Command To Program

Dec 2, 2013

I'd like to add a 'command' to my C program. For example if someone types 'get out' it closes the shell and quits. I want the 'get out' command to work like 'exit'. How do I write a code like this

Code:
char entry[15];
scanf("%[^
]", &entry);
if (entry = "get out")
do "exit";

View 14 Replies View Related

C# :: Program Keeps Adding 1 To Result?

Oct 21, 2014

I am creating a program that allows the user to enter the number of days worked and calculates the amount of money gained by doubling the amount from the previous day, starting with .01 cents. The program works fine except for in day 3, the program adds .01 along with doubling the amount from day 2. Also I must use a List Box.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;

[code]....

View 3 Replies View Related

C :: Strcpy - How To Update Old String In Stars Array With New That Includes Correct Letters

Apr 25, 2013

This for loop replaces the stars ******** in an array that contains a word to be guessed with the correct letter (c) that the user inputs if the word contains that letter.

Problem: After every guess the same hidden string of stars ******* is displayed instead of ex: ***W**** (assuming W was entered by the user)

How can I update the old ******** string in the Stars array with the new string that includes the correct letters chosen, so after every correct guess at a letter in the word a new string is displayed including the correct letters chosen?

I'm pretty sure I have to use strcpy but not sure how to implement it using a loop.

Code:
for(i = 0; i < strlen(unscrambledWord); i++) {
if(unscrambledWord [i] == c) {
Stars[i] = c;
} }

View 1 Replies View Related

C :: Making A Parallelogram That Prints 5 Stars And A Line Break With Increasing Spaces

Sep 12, 2013

All I have so far is a rectangle that prints 5 stars in length and 20 lines in length. What I want to do now is have each new line print an extra space more than the line before it and then print 5 stars.. This is what I have so far:

Code:

#include <stdio.h>
int main (void){
int i;
for(i=1; i<=20; i++){
printf("*****
");

[code]....

View 1 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved