Variables and Math
sokin
Posts: 32
in Propeller 1
Hello, I am just starting out with an activitybot and having trouble.
I am doing the variables and math tutorial. at the ending when it says "your turn, Expand Test Binary Operators.c so that it goes through testing all five binary operators in the Did You Know section".
Here is what I have and keep getting errors, what am I doing wrong?
/*
Variables and Calculations.c
Add two integer values together and display the result.
http://learn.parallax.com/propeller-c-start-simple/variables-and-math
*/
#include "simpletools.h" // Include simpletools
int main() // main function
{
int a = 25; // Initialize a variable to 25
int b = 17; // Initialize b variable to 17
int c = a + b; // Initialize c variable to a + b
print("a = %d, b = %d/n", a, b);
print("a + b = %d/n", c);
c = a - b;
print("a = %d, b = %d/n", a, b);
print("a - b = %d/n", c);
c = a / b;
print("a = %d, b = %d/n", a, b);
print("a / b = %d/n", c);
c = a * b;
print("a = %d, b = %d/n", a, b);
print("a * b = %d/n", c);
"c = a %% b";
print("a = %d, b = %d/n", a, b);
print("a %% b = %d/n", c);
}
Also the next question it asks "Try declaring int variables of y, m, and b, and then use them to calculate and display y = m*x + b".
Which specific variables should be switched to y, m and b? And what is x supposed to be?
Thanks for your response
I am doing the variables and math tutorial. at the ending when it says "your turn, Expand Test Binary Operators.c so that it goes through testing all five binary operators in the Did You Know section".
Here is what I have and keep getting errors, what am I doing wrong?
/*
Variables and Calculations.c
Add two integer values together and display the result.
http://learn.parallax.com/propeller-c-start-simple/variables-and-math
*/
#include "simpletools.h" // Include simpletools
int main() // main function
{
int a = 25; // Initialize a variable to 25
int b = 17; // Initialize b variable to 17
int c = a + b; // Initialize c variable to a + b
print("a = %d, b = %d/n", a, b);
print("a + b = %d/n", c);
c = a - b;
print("a = %d, b = %d/n", a, b);
print("a - b = %d/n", c);
c = a / b;
print("a = %d, b = %d/n", a, b);
print("a / b = %d/n", c);
c = a * b;
print("a = %d, b = %d/n", a, b);
print("a * b = %d/n", c);
"c = a %% b";
print("a = %d, b = %d/n", a, b);
print("a %% b = %d/n", c);
}
Also the next question it asks "Try declaring int variables of y, m, and b, and then use them to calculate and display y = m*x + b".
Which specific variables should be switched to y, m and b? And what is x supposed to be?
Thanks for your response
Comments
y=m*x+b is the equation of a line where y is the vertical (dependent) variable and x the horizontal (independent) variable.
X is just a list of numbers. For example Later you can learn about "for" loops so you won't have to have all that duplicated code.
hope this helps.
Tom