need some suggestions from the experts

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
28
29
30
31
32
33
34
35
#include <iostream>  
using namespace std;

    int main()  
    {  
        int i, j, k,a;
		a=9;		
          
        for (i=0; i<=a; i+=2)  
        {  
           for(j=0; j<a-i; j+=2)  
           {  
              cout<<" ";  
           }  
           for(k=0; k<=i; k++)  
           {  
              cout<<"*";
           }  
           cout<<endl;  
        }  
        a=a-2;  
        for(i=0; i<a; i+=2)  
        {  
           for(j=0; j<=i+2; j+=2)  
           {  
              cout<<" ";  
           }  
           for(k=1; k<=a-i;k++)  
           {  
              cout<<"*";  
           }  
           cout<<endl;  
        }  
        return 0;  
   }


program is without color. I need help to create a different color in each row. give me a bit of learning to solve.

thanks for the replies.
Last edited on
C++ does not understand colour. It does not understand what a monitor even is. If you want colour in the output, it depends entirely on your operating system and the console program you are using to display the output.

What is your operating system?
@Moschops

I use windows xp.
@Moschops

I just want a little extra code in the above program so that the output has a different color in each row
Here is the little extra code you need. I took it from the link I gave you.

#include <windows.h>

1
2
HANDLE hConsole;
hConsole = GetStdHandle(STD_OUTPUT_HANDLE);


1
2
k = 7;
SetConsoleTextAttribute(hConsole, k);


If you can't piece that together yourself from the very simple code, you're not ready for colours and you should go back to learn about functions.



There is an article on this site about console colours:
http://www.cplusplus.com/articles/2ywTURfi/

You just need to copy the code.
It is windows specific.
Topic archived. No new replies allowed.