Thread: Help...Help...Help...

  1. #1
    Registered User
    Join Date
    Dec 2003
    Posts
    10

    Help...Help...Help...

    Can some one fix this for me?
    It has been a long time since I've used C and I'm having trouble with changing the text color and clear screen as you'll see...

    Code:
    #include<stdio.h>
    #include<conio.h>
    #include<math.h>
    #define   MAX  7
    int main(void)
    {
    
    	float m[MAX],f[MAX],t[MAX];
    	int i;
    	float max,min,avr;
    	for(i=0;i<MAX;i++)
    	{
    		scanf("%g%g",&m[i],&f[i]);
    
    		t[i]=0.3*m[i]+0.7*f[i];
    	}
    	
    	max=min=avr=t[0];
    
    	for(i=1;i<MAX;i++)
    	{
    		avr=avr+t[i];
    		if(max<t[i])
    			(max=t[i]);
    		if(min>t[i])
    			(min=t[i]);
    	}
    	avr=avr/MAX;
    
    	//clrscr();  what is this??!!!!!!!
    
    
    	for(i=0;i<MAX;i++)
    	{
    		if(t[i]<10)
    			textcolor(12);
    		else if(t[i]>12);
    			textcolor(10);
    		else
    			textcolor(14);
    
    		cprintf("%-8.2lg%-b.2lg%-8.2lg\n\n", m[i],f[i],t[i]);
    	}
    
    	textcolor(15);
    
    	cprintf("\n\n\rMAX=%lg\n\r MIN=%lg\n\r AVR=%lg\n\r", max,min,avr);
    
    	return (0);
    
    }

  2. #2
    Registered User kryptkat's Avatar
    Join Date
    Dec 2002
    Posts
    638

    clrscr()

    clrscr() clears screen just un comment it

  3. #3
    Been here, done that.
    Join Date
    May 2003
    Posts
    1,164

    Re: Help...Help...Help...

    Originally posted by Pooyae
    Can some one fix this for me?
    Your really need to:
    1) give an appropriate title to your posts
    2) tell us what really is wrong with your code. This thing won't even compile.
    3) Don't ask us to "fix this for me" but ask "the problem seems to be ...., any ideas what might be wrong?"

    Try compiling the code, look at the line number(s) where the compiler has a problem, and check your semi-colons. They are not correct in that area.
    Definition: Politics -- Latin, from
    poly meaning many and
    tics meaning blood sucking parasites
    -- Tom Smothers

  4. #4
    Registered User
    Join Date
    Dec 2003
    Posts
    10
    It does not recognize clrscr() , it says undeclared identifier.
    the same for text color.

    And fyi, this is not my program, someone told me to fix this for them and i'm not an expert in C but rather VB. so any help is appreciated.

    And ofcourse it doesn't compile! DUH! if it did I wouldn't have a problem!

    thanx,
    -Pooya
    Last edited by Pooyae; 12-28-2003 at 12:42 PM.

  5. #5
    Been here, done that.
    Join Date
    May 2003
    Posts
    1,164
    Originally posted by Pooyae
    It does not recognize clrscr() , it says undeclared identifier.
    the same for text color.
    Then your compiler does not have those functions -- and may not be able to deal with color and clearing the screen.

    The Borland 5.5 compiler works -- I got it compiled and after further modification, it runs.

    It's a free compiler, so check Borland's site for it.
    http://www.borland.com/products/down..._cbuilder.html


    Originally posted by Pooyae
    And fyi, this is not my program, someone told me to fix this for them and i'm not an expert in C but rather VB. so any help is appreciated.
    Figured it wasn't your code.

    Originally posted by Pooyae
    And ofcourse it doesn't compile! DUH! if it did I wouldn't have a problem!
    Wanna bet? Once yours compiles, it will NOT work, so DUH! back.

    We're not psychic, you didn't mention it doesn't compile, how would we know this? Many programs don't work but compile fine.
    Definition: Politics -- Latin, from
    poly meaning many and
    tics meaning blood sucking parasites
    -- Tom Smothers

  6. #6
    Registered User
    Join Date
    Dec 2003
    Posts
    10
    Sorry for the misunderstandig, I didn't mean to be rude...

    Thanx, for your help.

    I'm using MS Visual C++ to dompile this, does it make a difference? Do different compilers use different C language?

    Thanx,
    -Pooya

  7. #7
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    Borland throws a lot of different functions and libraries into their compilers that aren't standard. Its not a different language per se since if you new how they did it you could do it also using regular C code.

  8. #8
    Been here, done that.
    Join Date
    May 2003
    Posts
    1,164
    Originally posted by Pooyae
    Sorry for the misunderstandig, I didn't mean to be rude...

    Thanx, for your help.

    I'm using MS Visual C++ to dompile this, does it make a difference? Do different compilers use different C language?

    Thanx,
    -Pooya
    When you get away from the standard and into compiler enhancements, which this graphics stuff is, each compiler has its own way of dsoing things.

    For MSVC++ look into the "SETxxx" functions (SetTextColor I believe) .
    Definition: Politics -- Latin, from
    poly meaning many and
    tics meaning blood sucking parasites
    -- Tom Smothers

  9. #9
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718
    On AdrianXW's website, there are tutorials for adding color to text, etc in MSVC++.
    Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

    You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

  10. #10
    Senor Member nomi's Avatar
    Join Date
    Jan 2004
    Posts
    129
    This compiles with dev-cpp but i;m not sure what its supposed to do....

    Code:
    #include<stdio.h>
    #include<conio.h>
    #include<math.h>
    
    #define   MAX  7
    
    int main(void)
    {
    
    	float m[MAX],f[MAX],t[MAX];
    	int i;
    	float max,min,avr;
    	
    	for(i=0;i<MAX;i++)
    	{
    		scanf("%g%g",&m[i],&f[i]);
    
    		t[i]=0.3*m[i]+0.7*f[i];
    	}
    	
    	max=min=avr=t[0];
    
    	for(i=1;i<MAX;i++)
    	{
    		avr=avr+t[i];
    		if(max<t[i])
    			(max=t[i]);
    		if(min>t[i])
    			(min=t[i]);
    	}
    	avr=avr/MAX;
    
    	clrscr();
    
    
    	for(i=0;i<MAX;i++)
    	{
    		if(t[i]<10){
    			textcolor(12);
    			}
    		else if(t[i]>12){
    			textcolor(10);
    			}
    		else textcolor(14);
    
    		printf("%-8.2lg%-b.2lg%-8.2lg\n\n", m[i],f[i],t[i]);
    	}
    
    	textcolor(15);
    
    	printf("\n\n\rMAX=%lg\n\r MIN=%lg\n\r AVR=%lg\n\r", max,min,avr);
    
    	return (0);
    
    }

Popular pages Recent additions subscribe to a feed