Tobriand
Well-Known Member
Is there a reason this shouldn't work (assuming I'm typing it in right).
Its supposed to be a simple loop proggy (not for GP32 obviously) to ask for a number, ask for a max for that number, then ask the ammount to increment it by and do so until it hits the max you set. You'll have to forgive my spacing... its not easy to get right in a text-box...
#include <stdio.h> /** and something else, but can't rememebr what the other one was off the top of my head **/
int i, maxi, inci;
main()
{
printf ("Please give a starting value for i: /n");
scanf ("%i", &i);
printf ("Now enter a starting value for maxi: /n");
scanf ("%maxi", &maxi);
printf ("Finally, a value to increment i by: /n");
scanf ("%inci", &inci);
while (i <= maxi) {
printf ("i is %i this time /n", i);
i = i + inci;
}
}
What actually happens when it's compiled is that the moment you enter a value - any value - for maxi and it jumps straight to a loop. Unfortauntely, it goes further and i shoots up to stupidly high numbers (>1000000) very quickly. A long way further than maxi, anyway. Setting all the values to 0 on declaring them doesn't seem to work either. Nor does replacing the while loop with a do {} while() one. My ide is kDevelop at the moment (since it came with Mandrake) - any tips?
Its supposed to be a simple loop proggy (not for GP32 obviously) to ask for a number, ask for a max for that number, then ask the ammount to increment it by and do so until it hits the max you set. You'll have to forgive my spacing... its not easy to get right in a text-box...
#include <stdio.h> /** and something else, but can't rememebr what the other one was off the top of my head **/
int i, maxi, inci;
main()
{
printf ("Please give a starting value for i: /n");
scanf ("%i", &i);
printf ("Now enter a starting value for maxi: /n");
scanf ("%maxi", &maxi);
printf ("Finally, a value to increment i by: /n");
scanf ("%inci", &inci);
while (i <= maxi) {
printf ("i is %i this time /n", i);
i = i + inci;
}
}
What actually happens when it's compiled is that the moment you enter a value - any value - for maxi and it jumps straight to a loop. Unfortauntely, it goes further and i shoots up to stupidly high numbers (>1000000) very quickly. A long way further than maxi, anyway. Setting all the values to 0 on declaring them doesn't seem to work either. Nor does replacing the while loop with a do {} while() one. My ide is kDevelop at the moment (since it came with Mandrake) - any tips?