Thread: maximum and minimum

  1. #16
    Registered User
    Join Date
    Dec 2008
    Posts
    17
    you are absolutely right! should I change every loop to the following:

    Code:
    for(n = 0; n < 1; n++)
    	{
    		char s[32];
    		sprintf(s, "&#37;.1f", ((maxx-minx)/5)*n);
    		Putstr(13, 14, s);
    	}

  2. #17
    Banned
    Join Date
    Dec 2008
    Posts
    49
    Thanks for giving me credit, but I would actually say Salem is absolutely right and you should simply change max = maxx-min;

  3. #18
    Registered User
    Join Date
    Dec 2008
    Posts
    17
    I said absolutely right to you because you said that I should make the last code on my on. But my code works ABSOLUTELY right now:
    Code:
    #include <stdio.h>
    #include <string.h>
    
    char xText[] = "Tid(sek)";
    char yText[] = "Temp(C)";
    
    char a[16][45] =
    {
    		{"                                             "},
    		{"                                             "},
    		{"              ^                              "},
    		{"              |                              "},
    		{"              |                              "},
    		{"              |                              "},
    		{"              |                              "},
    		{"              |                              "},
    		{"              |                              "},
    		{"              |                              "},
    		{"              |                              "},
    		{"              |                              "},
    		{"              |                              "},
    		{"              +---|---|---|---|---|->        "},
    		{"                                             "},
    		{"                                             "}
    };
    
    void Putstr(int x, int y, const char* s)
    {
    	int i;
    	for(i = 0; s[i]; i++)
    		a[y][x + i] = s[i];
    }
    void Putstr1(int x, int y, const char* s)
    {
    	int i;
    	for(i = 0; s[i]; i++)
    		a[x][y + i] = s[i];
    }
    
    int main()
    {
    	int l, i;
    	double minx;
    	double maxx;
    	double miny;
    	double maxy;
    	int n;
    
    	printf("Minimums og maksimums v&#230;rdi p&#229; x-aksen: ");
    	fflush(stdout);
    	scanf("&#37;lf, %lf", &minx, &maxx);
    	printf("Minimums og maksimums v&#230;rdi p&#229; y-aksen: ");
    	fflush(stdout);
    	scanf("%lf, %lf", &miny, &maxy);
    
    	// x-aske intervalv&#230;rdier:
    
    	for(n = 0; n < 1; n++)
    	{
    		char s[32];
    		sprintf(s, "%.1f", ((maxx-minx)/5)*n);
    		Putstr(13, 14, s);
    	}
    
    	for(n = 1; n < 2; n++)
    	{
    		char t[32];
    		sprintf(t, "%.1f", ((maxx-minx)/5)*n);
    		Putstr(17, 15, t);
    	}
    	for(n = 2; n < 3; n++)
    	{
    		char u[32];
    		sprintf(u, "%.1f", ((maxx-minx)/5)*n);
    		Putstr(21, 14, u);
    	}
    	for(n = 3; n < 4; n++)
    	{
    		char v[32];
    		sprintf(v, "%.1f", ((maxx-minx)/5)*n);
    		Putstr(24, 15, v);
    	}
    	for(n = 4; n < 5; n++)
    	{
    		char b[32];
    		sprintf(b, "%.1f", ((maxx-minx)/5)*n);
    		Putstr(29, 14, b);
    	}
    	for(n = 5; n < 6; n++)
    	{
    		char d[32];
    		sprintf(d, "%.1f", ((maxx-minx)/5)*n);
    		Putstr(32, 15, d);
    	}
    
    	// y-aske intervalv&#230;rdier:
    
    	for(n = 0; n < 1; n++)
    	{
    		char e[32];
    		sprintf(e, "%.f", ((maxy-miny)/5)*n);
    		Putstr(11, 13, e);
    	}
    	for(n = 1; n < 2; n++)
    	{
    		char r[32];
    		sprintf(r, "%.1f", ((maxy-miny)/5)*n);
    		Putstr(8, 11, r);
    	}
    	for(n = 2; n < 3; n++)
    	{
    		char g[32];
    		sprintf(g, "%.1f", ((maxy-miny)/5)*n);
    		Putstr(8, 9, g);
    	}
    	for(n = 3; n < 4; n++)
    	{
    		char f[32];
    		sprintf(f, "%.1f", ((maxy-miny)/5)*n);
    		Putstr(8, 7, f);
    	}
    	for(n = 4; n < 5; n++)
    	{
    		char h[32];
    		sprintf(h, "%.1f", ((maxy-miny)/5)*n);
    		Putstr(8, 5, h);
    	}
    	for(n = 5; n < 6; n++)
    	{
    		char m[32];
    		sprintf(m, "%.1f", ((maxy-miny)/5)*n);
    		Putstr(7, 3, m);
    	}
    
    	memcpy(a[1] + 10, yText, strlen(yText));
    	memcpy(a[13] + 45 - strlen(xText), xText, strlen(xText));
    
    	for(l = 0; l < 16; l++,printf("\n"))for(i=0; i<45; i++)
    	{
    		printf("%c", a[l][i]);
    	}
    
    	return 0;
    }
    Thank you BOTH guys for this help. Iam really grateful

  4. #19
    Banned
    Join Date
    Dec 2008
    Posts
    49
    You are welcome, but I would feel embarassed to say I feel like I helped you while you still have those nasty loops in your code

  5. #20
    Registered User
    Join Date
    Dec 2008
    Posts
    17
    Yes I think they really fills the space. I've tried to look a bit in my book about how to make them smaller, but I could not find anything. And since I am new to the profession, I have made the loops as easy as possible

  6. #21
    Banned
    Join Date
    Dec 2008
    Posts
    49
    You know that the vertical ticks are every 2 spaces and the horizontal spaces are every 4 spaces and vary by one vertical unit up or down. So why not utilize these facts and write a separate function.

  7. #22
    Registered User
    Join Date
    Dec 2008
    Posts
    17
    I think I'm not quite with. But it is something like:

    Code:
    int n;
       for(n = 0; n < 6; n++)
       {
          char s[32];
          sprintf(s, "%lf", max*n/6)
          PutStr(13 + 4*n, 14, s)
       }

  8. #23
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    > I think I'm not quite with. But it is something like:
    Absolutely!
    It's just a matter of working out the expression which positions the output in a regular pattern.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  9. #24
    Registered User
    Join Date
    Dec 2008
    Posts
    17
    Can I do It like this:

    Code:
    for(n = 0; n < 6; n++)
    	{
    		char s[32];
    		
    		sprintf(s, "%.1f", ((maxx-minx)/5)*n);
    		Putstr(13, 14, s);
    		
    		sprintf(s, "%.1f", ((maxx-minx)/5)*n);
    		Putstr(17, 15, s);
    		
    		sprintf(s, "%.1f", ((maxx-minx)/5)*n);
    		Putstr(21, 14, s);
    		
    		sprintf(s, "%.1f", ((maxx-minx)/5)*n);
    		Putstr(24, 15, s);
    		
    		sprintf(s, "%.1f", ((maxx-minx)/5)*n);
    		Putstr(29, 14, s);
    		
    		sprintf(s, "%.1f", ((maxx-minx)/5)*n);
    		Putstr(32, 15, s);
    	}

  10. #25
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Since you write 6 things each time through the loop, which runs six times (0,1,2,3,4,5) you will write 6*6=36 labels. Since you want 6 labels, and the loop runs six times, you need to print *1* thing inside the loop.

  11. #26
    Registered User
    Join Date
    Dec 2008
    Posts
    17
    Code:
    sprintf("&#37;.1f", ((maxx-minx)/5*n)
    Putstr(13, 14, *1*)
    Or am I completely wrong??

  12. #27
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Quote Originally Posted by aslak View Post
    Code:
    sprintf("%.1f", ((maxx-minx)/5*n)
    Putstr(13, 14, *1*)
    Or am I completely wrong??
    Yes. I was being emphatic -- 1 thing, not the actual number 1 with stars on it. And also you need to move the thing around -- if you write all six labels in the same place, well you won't see them all.

  13. #28
    Registered User
    Join Date
    Dec 2008
    Posts
    17
    For the x-axe, I have this loop:

    Code:
    for(n = 0; n < 6; n++)
    	{
    	   char s[32];
    	   sprintf(s, "&#37;.1f", ((maxx-minx)/5)*n);
    	   Putstr(13 + 4*n, 14 + (n % 2), s);
    	}
    But for the y-axe, I cant understand how the loop is going to be.

  14. #29
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Quote Originally Posted by aslak View Post
    For the x-axe, I have this loop:

    Code:
    for(n = 0; n < 6; n++)
    	{
    	   char s[32];
    	   sprintf(s, "%.1f", ((maxx-minx)/5)*n);
    	   Putstr(13 + 4*n, 14 + (n % 2), s);
    	}
    But for the y-axe, I cant understand how the loop is going to be.
    Why do you think it will be different? Change maxx to maxy, minx to miny, switch the Putstr around so you're going up instead of over, and you're done.

  15. #30
    Registered User
    Join Date
    Dec 2008
    Posts
    17
    when I try to plot this, i do not see anything at the coodinatesystem:

    Code:
    for(n = 0; n < 6; n++)
    	{
    	   char s[32];
    	   sprintf(s, "&#37;.1f", ((maxy-miny)/5)*n);
    	   Putstr(13 + 4*n, 14 + (n % 2), s);
    	}
    I want it to be different because I want the y-axe to be like this: 0 (and not 0.0) , 20.0 , 40.0 , 60.0 , 80.0 , 100.0.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 05-28-2009, 09:58 PM
  2. Displaying Minimum and Maximum values from input
    By mgardnertech in forum C Programming
    Replies: 1
    Last Post: 06-29-2008, 08:47 PM
  3. Maximum and Minimum Values
    By swaugh in forum C Programming
    Replies: 7
    Last Post: 12-16-2006, 09:43 PM
  4. Maximum And Minimum
    By drdodirty2002 in forum C++ Programming
    Replies: 2
    Last Post: 10-19-2004, 12:39 AM
  5. Replies: 2
    Last Post: 10-31-2002, 07:27 PM