triple pyramid

hi im new in c++ and im making a three pyramid which depend the size and form in input file so far i can only make one and theres so much a lot to input in my code

in problem it state that the first line contains the number of input to be read. for each line of input, display three pyramids using the character symbol and given size where 0 <= size of pyramid <= 30. the first and last pyramid are exactlty one less than the size of the middle pyramid. the three pyramids are seperated by exactly three spaces, for invalid input, display "no output"

this is the sample from input file
4
4*
5@
3+
31=

the output

          *
  *      * *      *
 * *    * * *    * *
* * *  * * * *  * * *
             @
   @        @ @        @
  @ @      @ @ @      @ @
 @ @ @    @ @ @ @    @ @ @
@ @ @ @  @ @ @ @ @  @ @ @ @
       +
 +    + +    +
+ +  + + +  + + 
no output

now here's my work
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include <iostream>
#include <fstream>
using namespace std;

int main()
{
     ifstream in;
     int num;
     char sym;
     in.open("sample.txt");
     
      while( in >> num  >> sym){
   for (int i=1;i<=num;i++){
      for (int k=1;k<=num;k++){
      cout << " ";
      }
   for (int x=1;x<=i;x++){
   cout << sym;
   cout << " ";
   }
   cout <<endl;
   num=num-1;
}
}

   return 0;
}


this is my file sample.txt

7*
6#
8!
9$

my output

    *
   * *
  * * *
 * * * *
   #
  # #
 # # #
     !
    ! !
   ! ! !
  ! ! ! !
      $
     $ $
    $ $ $
   $ $ $ $
  $ $ $ $ $

im having hard time on how to read only first line of the file also and adding two more pyramid, any help for this? tnx
Last edited on
Please indent your code.
You could use an auxiliary buffer
sorry im also new in forum so im not familiar here.
Topic archived. No new replies allowed.