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
ADVERTISEMENT
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
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
Jun 21, 2013
Similar to Pascal’s triangle, the difference triangle has some interesting properties that find applications in various fields of the natural and applied sciences. In simple terms, a difference triangle is a set of integers arranged in an inverted triangle where each inverted triangle triad has its lower element equal to the difference (absolute value) of the two elements in the upper row. A difference triangle can be created from a sequence of integers forming the uppermost row by iteratively taking differences between consecutive terms to form the next row until a single-element row is created.
Example Consider the sequence 5, 8, 13, 21, 34, 55 from the Fibonacci series as the uppermost row of the difference triangle. The difference between successive elements form a new set: 3 (= 8 – 5), 5 (= 13 – 8), 8 (= 21 – 13), 13 (= 34 – 21), and 21 (= 55 – 34). The process can then be repeated until there is only one element left giving the following difference triangle:
5 8 13 21 34 55
3 5 8 13 21
2 3 5 8
1 2 3
1 1
0
Problem Write a program that forms a difference triangle using a given series of numbers as topmost row.
View 2 Replies
View Related
Oct 6, 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:
1*******
2 *****
3 ***
(this pyramid is centered, in case it isnt when its posted). Also, each descending row has two less asteriks than the above row.
I am having trouble with the four loop displaying the number of "*" and " ". I know its a relationship with variables in the for loops, my output is just never doing what i want it to.
THis is the guideline for the for loop:
Use for loops to display the inverted trapezoid. Your outer for loop will iterate the total number of rows times. For each row use one nested for loop to display blanks (the 1st row contains no blanks) and another nested for loop to display the characters '*'.
Heres my for loops so far:
for (i = nrows; i >= 1; i--) {
for (j = 0; j >= nrows; j++) {
cout << " ";
} for (k=ntop; k >= 2; k--) {
cout << "*";
} }
The ouput is just blank as of now.
View 2 Replies
View Related
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
Mar 21, 2013
How to solve this (for cycle)?
View 12 Replies
View Related
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
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
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
View Related
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
Jul 20, 2013
I'm trying to display the contents of this map. I'm having some trouble where the program ceasing to display after "Index Contents."(lines 33 -40) If I move the display for loop right where I'm inserting the values (line 52) into the map I get output. I'm not sure where bug is.
#include <iostream>
#include <fstream>
#include <vector>
#include <sstream>
#include <regex>
#include <iterator>
#include <algorithm>
#include <string>
#include <map>
using namespace std;
typedef istream_iterator<string> isIterator;
typedef map<string, string> indexMap;
[Code] ....
View 1 Replies
View Related
Mar 5, 2015
I am trying to write a c program to convert centimeters to inches and then to feet. I have most of the code written but not sure how to debug it. I keep getting "0" as all of my output.
#include <stdio.h>
// Main Function
int main(void)
[Code]....
View 2 Replies
View Related
Jan 6, 2012
I got assignment at my school to display 2D array like this:
This is default array:
1 2 3 4
5 6 7 8
9 10 11 12
13 14 15 16
Now I have to print the default array like this:
1 2 6 7
3 5 8 13
4 9 12 14
10 11 15 16
I have tried some codes to do it myself but i had no success.
View 1 Replies
View Related
Feb 11, 2014
I have turbo c++ on windows xp SP2.....whenever i compile my code in turbo c++ i am getting output outside the screen.....but when i used code::block....i get the correct output...fits to screen ...
View 7 Replies
View Related
Feb 24, 2013
I'm trying to display an image from a stream data. But there is no image when getting image::from stream.
It's my source code:
Code:
IStream* pstream = NULL;
if(SUCCEEDED(CreateStreamOnHGlobal(NULL, TRUE, &pstream))) {
ULONG lreal = 0;
pstream->Write(chIncomingDataBuffer, iEnd, &lreal );
[Code]...
There is no image from data.
View 5 Replies
View Related
Jun 30, 2014
I'm currently working on a temperature conversion program using arrays / pointers as practice.
I will post the code below, its quite a bit lengthy and its also incomplete. Everything was going smoothly and I continually test my code as I write to completion, then I ran into a small road block.
My problem here is regarding the output from the first if statement in main. When I enter a value to convert from F to C. It successfully converts the first value I enter, but any other value after the first one during the loop in the first if statement, just shows long numbers of all sorts.
The output looks like this:
I kept checking the logic behind what I did, and for me it seems to be correct. Here is the code:
Code:
#include <stdio.h>
#define array_size 5
#define NEWLINE printf("
")
[Code].....
View 4 Replies
View Related
Oct 7, 2014
merging two arrays together and displaying them together in the end. However, I do not know how to start the merge function.
#include <iostream>
#include <assert.h>
using namespace std;
struct Array {
int* array; // point to the dynamically allocated array
}
[code]....
View 1 Replies
View Related
May 9, 2014
I am trying write a void function which will tally up the totals for each day and then display the most profitable day of the week.
#include "stdafx.h"
#include <iostream>
using namespace std;
#include <iomanip>
#include <string>
#include <fstream>
struct Menu_Items {
string Item;
double Price;
[Code] .....
The void function must pass as a parameter a pointer to the first element of the Orders_Placed array. I have attempted to write this. But I do not think I am even close. I need to have 7 double variables that hold the totals for each day of the week. Those are the MonTotals , TueTotals , etc....
How do I get these totals for each day?
How do I fix this void function so that is displays the most profitable day. Also, would the function call be Biggest_Profit(Orders_Placed)??
The GetPrice function provides the price given a menu item.
View 1 Replies
View Related
Oct 6, 2013
If the number 4 is entered, the output should be the following:
1: 1
2: 1, 2
3: 1, 3
4: 1, 2, 4,
My output, however, is different but I know its an error with the comma.f
1: 1, , ,
2: 1, 2, ,
3: 1, , 3,
4: 1, 2, , 4
Here is my code:
#include <iostream>
using namespace std;
int main()
{
[Code].....
View 1 Replies
View Related
Feb 14, 2013
I've finally been able to get my coding corrected after doing this for 5 hours and watching numerous tutorials on it... But I now need to create a table. how to create a table with dashed lines like -----------------, both vertical and horizontal.
Another issue I have is that I'm having trouble trying to get a prompt to ask the user how many programs, tests, and quizzes he/she completed with their total points. I got the basic programming done, but need a prompt asking "How many (quizzes, tests, or programs) have you completed?"
Finally, the do-while loop is driving me insane, where I have to set certain values. If it is greater than 2, then I insert formula 1, but if it is less than 2, then I insert formula 2. Whichever way it goes, the total points earned minus the two lowest scores are then calculated into an average.
Code:
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
int main()
[code]....
The whole basis of the program is to calculate the averages of programs, tests, and quizzes done during a semester at a school. The user is asked how many of each category he/she has completed (total points earned and total points possible). All of this is then calculated into a cumulative class average in a table along with points earned and points possible for each category (along with tests and quizzes combined into one average along with individual averages).
View 2 Replies
View Related
Jan 7, 2015
I have started working with structures so here's a side project from my text book. It's purpose is fairly simple; it asks for the sales of each quarter of the year from 4 different divisions and then calculates the average quarterly sales and total annual sales and finally displays all the data. My problem is that in the function "displayCompanyInfo" the statement
std::cout << "Division " << R.division_name << std::endl;
does not display the name of the division. With that in mind here is the code:
#include <iostream>
#include <string>
struct CompanyInfo
{
[Code]....
As you can see the last part of the output has statements that say "Division" however they do not say the name of the division afterwards. I don't understand why that is?
View 2 Replies
View Related
Feb 16, 2014
I used getline to import EMPLOYEE's First and Last Name from a txt file. After calculating the weights ans stuff. Now when i try to write to output txt file am having the below issue in which its not putting it in one line.
***CODE***
fout << "Note: This report for " << employee << " was prepared according to the fair practice of the University." << endl ;
***THIS IS WHAT ITS PRINTING***
Note: This report for FIRSTNAME LASTNAME was prepared according to the fair practice of the University.
I also tried like this;
***CODE***
fout << "Note: This report for " << getline(fin, employee) <<" was prepared according to the fair practice of the University." << endl ;
***THIS IS WHAT ITS PRINTING***
Note: This report for 0 was prepared according to the fair practice of the University.
this second code puts everything in one line but its showing 0 (zero) instead of the employee's first and last name.
View 4 Replies
View Related
Feb 20, 2013
When this programs runs it displays odd symbols for the address of the character. This is only part of the program, I took out the parts that already work.
#include <iostream>
using namespace std;
char again;
[Code].....
View 2 Replies
View Related
Apr 4, 2014
Not Displaying tree elements. Here is the code. Want to know the error.
#include <iostream>
struct TreeNode
{
int number;
TreeNode* left;
TreeNode* right;
};
struct Tree
[Code]...
View 1 Replies
View Related
Mar 6, 2013
I am trying to display a messagebox, but instead of just displaying the message box, there is also a console the pops up. How do I prevent the console from popping up? I'm using Visual Studio 2012. I'm creating an empty project, but I still get the console.
View 1 Replies
View Related