help with a script

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
bushez
Posts: 60
Joined: 16 Nov 2015, 15:36

help with a script

11 Nov 2017, 05:00

so what i want it to do is when i enter a number between 0-9999 it will give me his min digit and max digit but its not working if someone can help tnx

Code: Select all

int main()
{
	int num, max, min;
	printf("Enter a number between 0 and 9999\n");
	scanf("%d", &num);
	min = num % 10;
	max = num % 10;
	num = (num / 10);

	if (num < 0)
	{
		printf("error number need to be between 0-9999\n");
	}
	else if (num > 9999)
	{
		printf("error number need to be between 0-9999\n");
	}
	else
	{



		if (min <= num % 10)
		{
			min = num % 10;
		}
		else if (max >= num % 10)
		{
			max = num % 10;
		}
		if (min <= num % 10)
		{
			min = num % 10;
		}
		else if (max >= num % 10)
		{
			max = num % 10;
		}
		if (min <= num % 10)
		{
			min = num % 10;
		}
		else if (max >= num % 10)
		{
			max = num % 10;
		}
		if (min <= num % 10)
		{
			min = num % 10;
		}
		else if (max >= num % 10)
		{
			max = num % 10;
		}
		printf("max digit = %d\n", max);
		printf("min digit = %d\n", min);
	}

	return 0;
}
SirRFI
Posts: 404
Joined: 25 Nov 2015, 16:52

Re: help with a script

11 Nov 2017, 05:25

It's not even AHK to begin with.

Assuming You want the most important and the lest important digit: Guess You could treat the number as string, or convert it to one, then just take the first and last character.
Assuming You want the lowest and the highest digit in the entire number: Can try splitting the number and assigning digits as new array keys (0 would be Arr[0], 5 would be Arr[5], 9 would be Arr[9], etc.), then just check the lowest and highest index in the array.
Both of these sounds better than whole bunch of ifs and mod(), and allows scalability.

Also You should validate input (num <0 && num > 9999) before doing anything else.
Use

Code: Select all

[/c] forum tag to share your code.
Click on [b]✔[/b] ([b][i]Accept this answer[/i][/b]) on top-right part of the post if it has answered your question / solved your problem.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Draken, haomingchen1998, ReyAHK and 253 guests