--SOLVED--
Hey everyone, i'm new to coding (just started my degree in electrical engineering and coding in C is part of it).
I'm trying to create and test a simple menu where the user can select options 1-4 and I set up two printf tests (1 within the function and 1 in the main function) to display the chosen option. x however is always shown has having the value of '1' and will not update to the choice. What have I done wrong? Thanks in advance!
Code:
#include <stdio.h>
int pay_select(void);
void main(void)
{
int choice = pay_select(); //run function where user selects option 1-4
printf("Test 2 = %d", choice); //print selected option
}
int pay_select(void)
{
int x;
puts("opt 1 = £5"); //pay options
puts("opt 2 = £10");
puts("opt 3 = £15");
puts("opt 4 = £20");
x = scanf("%d", &x); //saves option selected
printf("Test 1 = %d\n", x);
return x;
}