How Do I Combine Multiple C++ Programs into One?

  • Context: C/C++ 
  • Thread starter Thread starter zarentina
  • Start date Start date
  • Tags Tags
    Programs
Click For Summary

Discussion Overview

The discussion revolves around combining multiple C++ programs into a single program that outputs four right triangles, each rotated and separated by tabs. Participants are exploring how to structure nested loops to achieve the desired output format.

Discussion Character

  • Homework-related
  • Technical explanation
  • Exploratory

Main Points Raised

  • One participant describes their goal of combining four different C++ programs to produce an output of four right triangles, each separated by tabs.
  • Another participant requests clarification on what the four programs should do and how the combined program should function.
  • One participant shares their code for the first triangle and expresses concern that the outputs are merging into a single block rather than displaying as separate triangles.
  • Another participant suggests improving code readability through indentation and clarifies the output format again.
  • A later reply provides a potential solution by presenting a combined code snippet that uses nested loops to print the triangles with tabs in between, but does not confirm its correctness.

Areas of Agreement / Disagreement

Participants generally agree on the goal of combining the programs to achieve the desired output format, but there is no consensus on the correctness of the current implementations or the proposed solutions.

Contextual Notes

Some participants express uncertainty about the structure of the loops and the output formatting, indicating that assumptions about the desired output may vary. There are unresolved issues regarding the merging of outputs and the correct placement of tabs.

zarentina
Messages
12
Reaction score
0
Hello all, I am still new to C++ and was instructed to write four programs all a bit different and eventually combine them into one using a series of nested for loops to get an out put that resembles but goes to 10 lines of output not 5: *NOTE* all these will be separated by a tab count<<"\t"

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

**Sorry for this the spaces were not showing up between the outputs, they are essentially 4 right triangles rotated and spaced by a tab.**

I have all of the individual programs written, and I can combine the second two without any hiccups yet when I try to combine the first two I begin to run into trouble.

My code for the first two is as follows;

#include<iostream>
using namespace std;
int main ()
{
int i,j,k, range=10;
for (i=0;i<10;i++)
{
for (j=0; j<=i; j++)
{
count<<"*";
}
count<<endl;
}

system("pause");
return 0;
}

and the second is:

#include<iostream>
#include <iomanip>
using namespace std;
int main ()
{
int i,j,k, range=10;
for (i=0;i<10;i++)
{
for (j=10; j>i; j--)
{
count<<"*";
}
count<<endl;
}
system("pause");
return 0;
}


I'm starting to think maybe my programs for the first two outputs are incorrect? For the second two I simply removed the "count<<endl;" and replaced it with count<<"\t"; but this doesn't seem to work for the first two.

Any advice would be greatly appreciated!
Thanks,
Z

p.s sorry for the lengthy post :/
 
Technology news on Phys.org
It won't hurt if you will explain what the four programs should do, and what the combined program should do.

Post you sources using code tags:

[noparse]
Code:
int main()
{
  return 0;
}
[/noparse]

is displayed as

Code:
int main()
{
  return 0;
}
 
Sorry about that, the four codes will combine which produces an output of four right triangles rotated and printed on the same lines. Such as was in my original post, yet for some reason those got pushed together and made it seem as one block of *'s not four triangles.My first program is the initial triangle.
Code:
 #include<iostream>
using namespace std;
int main ()
{
int i,j,k, range=10;
for (i=0;i<10;i++)
{
for (j=0; j<=i; j++)
{
cout<<"*";
}
cout<<endl;
}

system("pause");
return 0;
}

My second program is the second triangle
Code:
 #include<iostream>
#include <iomanip>
using namespace std;
int main ()
{
int i,j,k, range=10;
for (i=0;i<10;i++)
{
for (j=10; j>i; j--)
{
cout<<"*";
}
cout<<endl;
}
system("pause");
return 0;
}

My goal is to combine them into one program using for loops while they remain in triangle shape separated by a tab.

Thanks,
 
Now that you're using code tags, your code would be more understandable if you indented it in a way that shows the logical structure, rather than having every line start at the left margin. I have done this with your code.
zarentina said:
Sorry about that, the four codes will combine which produces an output of four right triangles rotated and printed on the same lines. Such as was in my original post, yet for some reason those got pushed together and made it seem as one block of *'s not four triangles.


My first program is the initial triangle.
Code:
#include<iostream>
using namespace std;
int main ()
{
   int i,j,k, range=10;
   for (i=0;i<10;i++)
   {
      for (j=0; j<=i; j++)
      {
         cout<<"*";
      }
      cout<<endl;
   }

   system("pause");
   return 0;
}

My second program is the second triangle
Code:
#include<iostream>
#include <iomanip>
using namespace std;
int main ()
{
   int i,j,k, range=10;
   for (i=0;i<10;i++)
   {
      for (j=10; j>i; j--)
      {
         cout<<"*";
      }
      cout<<endl;
   }
   system("pause");
   return 0;
}

My goal is to combine them into one program using for loops while they remain in triangle shape separated by a tab.

Thanks,
 
May be help with you.
Code:
#include <iostream>

using namespace std;

#define MATRIX_SIZE 10  //change it to any size you want to show at here

int main()
{
	int i,j;
	for (i = 0;i < MATRIX_SIZE;i++)
	{
		for (j = 0 ; j < i+1; j++)
		{
			cout<<"*";
		}

		//cout<<" ";   //I think may be this line is what you want
		cout<< "\t"; 
 
		for ( ;j <= MATRIX_SIZE ; j++)
		{
			cout<<"*";
		}
		cout<<endl;
	}
	system("pause");
	return 0;
}
 

Similar threads

Replies
12
Views
3K
  • · Replies 15 ·
Replies
15
Views
4K
  • · Replies 25 ·
Replies
25
Views
3K
Replies
12
Views
2K
  • · Replies 6 ·
Replies
6
Views
12K
  • · Replies 40 ·
2
Replies
40
Views
3K
  • · Replies 10 ·
Replies
10
Views
3K
  • · Replies 30 ·
2
Replies
30
Views
4K
Replies
3
Views
1K
Replies
73
Views
6K