I need help with a program

Joined
Apr 17, 2023
Messages
2
Reaction score
0
I'm learning to code in C with the help of a friend, but a code that I'm trying to write doesn't work
int number (int x) {
int n = 2 * x + 4;
return n;
}
int main () {
int x = 10;
printf("The answer is %d\n", n);
}
What I'm trying to do is for the formula to get solved with the input from int main, but it just tells me that x inst defined. I tried swapping around some of the intigers, but it doesn't work at all.
 
Joined
Sep 4, 2022
Messages
128
Reaction score
16
C:
int number (int x) {
return 2 * x + 4;

}
int main () {
int x = 10;
printf("The answer is %d\n", number(10));
printf("The answer is %d\n", number(x));
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,534
Members
45,008
Latest member
Rahul737

Latest Threads

Top