The question I am working on is
"given a = 5, b = 1, x = 10, and y = 5, create a program that outputs the result of the formula f = (a - b )(x - y) using a single printf() function"
So far I have
#include
main()
{
intF = (5 - 1) * (10 - 5);
}
When I run it in cygwin I just get errors. I really don't know anything about programming but am forced to take this beginner course.
Any help with this would be really appreciated.
When declaring variables you have to set the type, for a number ( or more commonly referred to as an integer ) you do this
int myInt;
That will create the integer 'myInt' with no value. To add a value, after its declaration, you can do this.
myInt = 10;
So now myInt is declared and is 10. I'm assuming your teacher wants you to declare each variable and assign its value, so to save from doing something like
int myIntfoo = 10;int myIntbar = 5;int myIntn = 1;
So on and so forth to declare all your variables on a new line, you can save time by declaring the type then each variable separated by commas.
int myIntfoo = 10, myIntbar = 5, myIntn = 1;
To add variables together, following my examples so far, you simply write something like this
int foobar = myIntfoo + myIntbar;
Now foobar will be 15. You can also, in the interest of saving variables, write something like this
myIntfoo = myIntfoo + myIntbar;
Which will again be 15. The same goes with multiplying, dividing, and subtracting. I'm not familiar with printf, embarrassingly enough, but I know you'll need to write something like
printf("foo: %1 \nbar: %2\nn: %3", (myIntfoo, myIntbar, myIntn));So it outputs the numbers given in their order or something, like I said I don't know how the flags work. Anyway, I hope I helped you a bit without doing all your homework for you.

Edit: I learned how to use printf() real quick and it's pretty simple. There may be a more concise way to print multiple variables, but I'll let someone else teach you how to do that.
Using the same variables, I'll write a working function to print them all out.
Your first problem was declaring main. Each function needs a type, just like a variable. main is a special function and
must be an int.
int main(){}I'm sure you already know how functions work after proper declaration. Now let's stick our variables inside.
int main(){ int myIntfoo = 10, myIntbar = 5, myIntn = 1, myIntsum; myIntsum = myIntfoo * myIntbar + myIntn;}As you can see, I added a new variable "myIntsum" and set it equal to a small equation using the other variables. Let's move onto using printf(), shall we? Let's run down how it works quickly.
printf(text, variable);
Text can be anything, and is where you include what are called "flags" which I'll show you how to use in a minute. Let's use printf() so it outputs myIntfoo.
printf("myIntfoo: %i", myIntfoo);%i is a flag, and it basically says that the variable ( as we went over before is the thing after the comma ) is an integer and to output it. So, altogether, we have the text simply saying "myIntfoo: 10". You'll see I use \n a lot, and all this does is have any preceding text on a new line. One last thing, simply for ease of use and good habits. getchar() is a simple function which, in the current use, waits for you to press a key until continuing on in the program. So, in the code below it just waits for you to press a key before exiting.
#include // two forward slashes is a single line comment/* a forward slash and asterisk is a multiline comment */int main(){ int myIntfoo = 10, myIntbar = 5, myIntn = 1, myIntsum; // declare variables myIntsum = myIntfoo * myIntbar + myIntn; printf("foo:%i\n",myIntfoo); // output myIntfoo printf("bar:%i\n",myIntbar); printf("n:%i\n",myIntn); printf("The sum:%i\n",myIntsum); getchar(); // wait for a key press and exit return 0;}