Thread: maximum and minimum

  1. #31
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    You can't print them in the same place as your x axis! You have to change the coordinates in Putstr around so that you print up the y-axis, not across the x-axis. And if you want 0 to be special, do it outside the loop (so that you would start n at 1 instead of 0).

  2. #32
    Registered User
    Join Date
    Dec 2008
    Posts
    17
    Okay I have tried to change my coorinate but it did not help.

    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;
    	Putstr(15, 12, "*");
    	Putstr(16, 12, "*");
    	Putstr(17, 11, "*");
    	Putstr(18, 10, "*");
    	Putstr(20, 9, "*");
    	Putstr(21, 8, "*");
    	Putstr(23, 7, "*");
    	Putstr(24, 5, "*");
    	Putstr(25, 6, "*");
    	Putstr(26, 5, "*");
    	Putstr(27, 4, "*");
    	Putstr(28, 4, "*");
    	Putstr(29, 5, "*");
    	Putstr(30, 6, "*");
    	Putstr(31, 6, "*");
    	Putstr(32, 6, "*");
    	Putstr(33, 5, "*");
    	Putstr(34, 5, "*");
    
    	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 < 6; n++)
    	{
    		char s[32];
    		sprintf(s, "%.1f", ((maxx-minx)/5)*n);
    		Putstr(13 + 4*n, 14 + (n % 2), s);
    	}
    
    	// y-akse intervalv&#230;rdier:
    	
    	for(n = 0; n < 6; n++)
    			{	
    				char t[32];
    				sprintf(t, "%.f", ((maxy-miny)/5)*n);
    				Putstr(10, 13, t);
    				sprintf(t, "%.1f", ((maxy-miny)/5)*n);
    				Putstr(8, 11, t);
    				sprintf(t, "%.1f", ((maxy-miny)/5)*n);
    				Putstr(8, 9, t);
    				sprintf(t, "%.1f", ((maxy-miny)/5)*n);
    				Putstr(8, 7, t);
    				sprintf(t, "%.1f", ((maxy-miny)/5)*n);
    				Putstr(8, 5, t);
    				sprintf(t, "%.1f", ((maxy-miny)/5)*n);
    				Putstr(8, 3, t);
    			}
    	
    		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;
    	}

  3. #33
    Registered User
    Join Date
    Dec 2008
    Posts
    17
    Okay I have tried to change my coorinate but it did not help.

    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;
    	Putstr(15, 12, "*");
    	Putstr(16, 12, "*");
    	Putstr(17, 11, "*");
    	Putstr(18, 10, "*");
    	Putstr(20, 9, "*");
    	Putstr(21, 8, "*");
    	Putstr(23, 7, "*");
    	Putstr(24, 5, "*");
    	Putstr(25, 6, "*");
    	Putstr(26, 5, "*");
    	Putstr(27, 4, "*");
    	Putstr(28, 4, "*");
    	Putstr(29, 5, "*");
    	Putstr(30, 6, "*");
    	Putstr(31, 6, "*");
    	Putstr(32, 6, "*");
    	Putstr(33, 5, "*");
    	Putstr(34, 5, "*");
    
    	printf("Minimums og maksimums værdi på x-aksen: ");
    	fflush(stdout);
    	scanf("%lf, %lf", &minx, &maxx);
    	printf("Minimums og maksimums værdi på y-aksen: ");
    	fflush(stdout);
    	scanf("%lf, %lf", &miny, &maxy);
    
    	// x-aske intervalværdier:
    
    	for(n = 0; n < 6; n++)
    	{
    		char s[32];
    		sprintf(s, "%.1f", ((maxx-minx)/5)*n);
    		Putstr(13 + 4*n, 14 + (n % 2), s);
    	}
    
    	// y-akse intervalværdier:
    	
    	for(n = 0; n < 6; n++)
    			{	
    				char t[32];
    				sprintf(t, "%.f", ((maxy-miny)/5)*n);
    				Putstr(10, 13, t);
    				sprintf(t, "%.1f", ((maxy-miny)/5)*n);
    				Putstr(8, 11, t);
    				sprintf(t, "%.1f", ((maxy-miny)/5)*n);
    				Putstr(8, 9, t);
    				sprintf(t, "%.1f", ((maxy-miny)/5)*n);
    				Putstr(8, 7, t);
    				sprintf(t, "%.1f", ((maxy-miny)/5)*n);
    				Putstr(8, 5, t);
    				sprintf(t, "%.1f", ((maxy-miny)/5)*n);
    				Putstr(8, 3, t);
    			}
    	
    		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;
    	}

  4. #34
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Again, you are printing six things inside the loop, which happens six times, for a grand total of thirty-six different things printing. You need to print one thing inside the loop, which happens five times (since you seem to want to do 0 special, so that would go before the loop).

    Just because you are doing the same thing that you did with the x-axis does not mean you have to make the same mistakes along the way. This was a merely silly thing to do the first time -- now that you know better, and have the right answer (more or less) already in your code, to do the same thing again is stupid.

  5. #35
    Registered User
    Join Date
    Dec 2008
    Posts
    17
    Okay, but when I try with almost the same loops I used in the x-axe, does it still not work:

    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);
    	}
    
    for(n = 0; n < 6; n++)
    	{
    		char s[32];
    		sprintf(s, "%.1f", ((maxy-miny)/5)*n);
    		Putstr(10 + 4*n, 14 , s);
    	}

  6. #36
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    You cannot change the Putstr coordinates at random! And even besides that, you are still going across, not up. Your coordinates were supposed to be (8,11), (8,9), (8,7), (8,5), (8,3) for n = 1 through 5. Do you think 10+4*n will give you 8, 8, 8, 8, and 8? Do you think that a y-coordinate that is 14 will somehow give you 11, 9, 7, 5, and 3?

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