you are absolutely right! should I change every loop to the following:
Code:for(n = 0; n < 1; n++) { char s[32]; sprintf(s, "%.1f", ((maxx-minx)/5)*n); Putstr(13, 14, s); }
you are absolutely right! should I change every loop to the following:
Code:for(n = 0; n < 1; n++) { char s[32]; sprintf(s, "%.1f", ((maxx-minx)/5)*n); Putstr(13, 14, s); }
Thanks for giving me credit, but I would actually say Salem is absolutely right and you should simply change max = maxx-min;
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:
Thank you BOTH guys for this help. Iam really gratefulCode:#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æ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 < 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æ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; }
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
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
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.
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) }
> 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.
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); }
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.
Or am I completely wrong??Code:sprintf("%.1f", ((maxx-minx)/5*n) Putstr(13, 14, *1*)
For the x-axe, I have this loop:
But for the y-axe, I cant understand how the loop is going to be.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); }
when I try to plot this, i do not see anything at the coodinatesystem:
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.Code:for(n = 0; n < 6; n++) { char s[32]; sprintf(s, "%.1f", ((maxy-miny)/5)*n); Putstr(13 + 4*n, 14 + (n % 2), s); }