Jan 30, 2011 at 1:58am UTC
I want to print a tricolor flag on the console screen using a nested for loop in c++.
But whenever I try to do so, i end up getting a straight line or a vertical ine.
Please help.
Last edited on Jan 30, 2011 at 1:59am UTC
Jan 30, 2011 at 2:26am UTC
I assume you mean the French flag, the 'drapeau tricolore':
1 2 3 4 5 6 7 8
#include "stdio.h"
int main(){
char const *setbluebg="\033[44m" ,
*setwhitebg="\033[47m" ,
*setredbg="\033[41m" ,
*setstop="\033[m" ;
for (int i=0;i<2;i++)printf("%s %s %s %s\n" ,setbluebg,setwhitebg,setredbg,setstop);
}
Last edited on Jan 30, 2011 at 2:29am UTC
Jan 30, 2011 at 2:35am UTC
I tried displaying the seven colors in order using the following code but it displays all the colours in a linear manner.
What's wrong with my code?
#include<conio.h>
#include<iostream.h>
void main()
{clrscr();
for(int i=1;i<256;i++)
{textcolor(2);
cout<<"\n";
for(int j=1;j<=12;j++)
{cprintf("Û"); }}
for(int a=1;a<256;a++)
{textcolor(3);
cout<<"\n";
for(int b=1;b<=12;b++)
{cprintf("Û"); }}
for(int s=1;s<256;s++)
{textcolor(4);
cout<<"\n";
for(int d=1;d<=12;d++)
{cprintf("Û"); }}
for(int f=1;f<256;f++)
{textcolor(5);
cout<<"\n";
for(int g=1;g<=12;g++)
{cprintf("Û"); }}
for(int h=1;h<256;h++)
{textcolor(6);
cout<<"\n";
for(int k=1;k<=12;k++)
{cprintf("Û"); }}
for(int l=1;l<256;l++)
{textcolor(7);
cout<<"\n";
for(int z=1;z<=12;z++)
{cprintf("Û"); }}
for(int x=1;x<256;x++)
{textcolor(8);
cout<<"\n";
for(int c=1;c<=12;c++)
{cprintf("Û"); }}
getch();
}
Jan 30, 2011 at 2:38am UTC
Everything about that code is wrong. Don't use conio.h.
Last edited on Jan 30, 2011 at 2:38am UTC