Thread: about coloring text

  1. #1
    and the Hat of Clumsiness GanglyLamb's Avatar
    Join Date
    Oct 2002
    Location
    between photons and phonons
    Posts
    1,110

    Question about coloring text

    Code:
    #include <stdio.h>
    #include <math.h>
    #include <time.h>
    # include <conio.h>
    	int main()
    	{
    
    
    
    		unsigned long r;
    		int toets2;
    
    		do{
    		int textcolor();
    		int sleep();
    		float a,b,c;			/*a,b,c variabele d is de discriminant,i is voor de loop*/
    		int i=100000;
    		int j=1050000000;
    		printf("\t\t\4WORTELFORMULE BEREKENEN\4\n\n\n");
    
    		printf("\tDe functie is van de vorm: ax*x+bx+c=0\n\n");
    
    		printf("\tGeef een waarde in voor a\n\n\t");
    		scanf("%f",&a);
    		printf("\ta=%.2f\n",a);
    
    		printf("\n\tGeef een waarde in voor b\n\n\t");
    		scanf("%f",&b);
    		printf("\tb=%.2f\n",b);
    
    		printf("\n\tGeef een waarde in voor c\n\n\t");
    		scanf("%f",&c);
    		printf("\tc=%.2f\n",c);
    
    
    		printf("\tEven geduld de computer berekent de discriminant\n");
    		sleep(500);
    		printf("\tD=wortel uit(b*b)-(4*a*c)\n");
    		sleep(500);
    		double d,dd,uitkomst1,uitkomst2;
    		d=b*b-4*a*c;
    		dd=sqrt (d);
    		uitkomst2=(-b-dd)/(2*a);
    		uitkomst1=(-b+dd)/(2*a);
    
    		if(d<0){
    
    				textcolor(LIGHTRED);
    				printf("\tFout wortel van %.2f kan niet!!!\n\n",d);
    				textcolor(LIGHTGRAY);
    				}
    
    		else{
    				textcolor(GREEN);
    				printf("\tD=%.2f\n\n",dd);
    				printf("\tx1=%.2f\n\n",uitkomst1);
    				printf("\tOf....\n\n");
    				printf("\tx2=%.2f\n\n",uitkomst2);
    				textcolor(LIGHTGRAY);
    				}
    
    
    		printf("\t\t\t-=Druk op toets 1 om af te sluiten=-\n");
    		printf("\t\t\t\t\tOf....\n-=Druk op 2 om opnieuw een vierkantsvergelijking op te lossen.=-\n\t\t\t\t\t");
    
    		scanf("%d",&toets2);
    
    		r=r-1;
    
    				}
    		while(toets2>=2);
    		
    		if(toets2==1)
    
    		return 0;
    	}
    1) this thing just calculates something and runs onder dos
    2) i use the lcc win32 compiler
    3) i want to use colors so when the sqrt<0 he is supposed to give an error in RED or LIGHTRED
    if the sqrt>0 then he has to give x1 and x2 in GREEN or LIGHTGREeN
    4) all of that works perfectly except for (now comes the prob):
    a)i use a do while loop and it works, the first time u run it
    the colors are displayed but if you press 2 at the end of the
    program it starts all over again but the problem is that he
    doesnt use the colors anymore, ive tried several ways and
    none of them worked
    b)also when the sqrt>0 he only gives of... in GREEN and the
    part where printf("x1=%.2f",uitkomst1); is NOT in GREEN
    i also have the same problem with
    printf("x2=%.2f",uitkomst2);
    So if ne1 knows how to solve this plz tell me
    Greetz
    Lamb

  2. #2

  3. #3
    and the Hat of Clumsiness GanglyLamb's Avatar
    Join Date
    Oct 2002
    Location
    between photons and phonons
    Posts
    1,110
    euhm doesnt any one wanna replie on this coz actually my question is very simple but mayb i should rephrase it ....

  4. #4
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    Originally posted by GanglyLamb
    euhm doesnt any one wanna replie on this coz actually my question is very simple but mayb i should rephrase it ....
    Rephrasing might be a good idea, I must admit I read it earlier and it didn't sink in, so I moved on. Maybe a short, clear example of the problem would be better.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  5. #5
    and the Hat of Clumsiness GanglyLamb's Avatar
    Join Date
    Oct 2002
    Location
    between photons and phonons
    Posts
    1,110

    Question

    ive made an exemple (a shorter one) to show what happens with my colors
    now i also use the do while loop and i work with variables within the loop
    and the funny thing is that in the short code the colors work BUT in the long one it doesnt but i cant see to find the error
    anyway ill have a look at it AGAIN

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A bunch of Linker Errors...
    By Junior89 in forum Windows Programming
    Replies: 4
    Last Post: 01-06-2006, 02:59 PM
  2. struct question
    By caduardo21 in forum Windows Programming
    Replies: 5
    Last Post: 01-31-2005, 04:49 PM
  3. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 09:54 AM
  4. Ok, Structs, I need help I am not familiar with them
    By incognito in forum C++ Programming
    Replies: 7
    Last Post: 06-29-2002, 09:45 PM
  5. Outputting String arrays in windows
    By Xterria in forum Game Programming
    Replies: 11
    Last Post: 11-13-2001, 07:35 PM