Shop OBEX P1 Docs P2 Docs Learn Events
Variables and Math — Parallax Forums

Variables and Math

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

Comments

  • twm47099twm47099 Posts: 867
    edited 2017-04-05 03:30
    In the third line from the bottom you have the equation c=a%% b; in quotation marks. There should not be any quotes. Also the modulus operator is %, not %%. The extra % is needed in print statements but not in the actual equation.

    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
    
    {
    int y ;  // don't actually need this unless you calculate y outside of the print statement.
    int m = 5;
    int b = 1;
    int x;
    x = 1;
    print ("x = %d   y= %d\n", x, m * x + b);
    x = 2;
    print ("x = %d   y = %d\n", x, m * x + b);
    x = 3;
    print ("x = %d   y = %d\n", x, m * x + b);
    x = 4;
    print ("x = %d   y = %d\n", x, m * x + b);
    }
    
    Later you can learn about "for" loops so you won't have to have all that duplicated code.
    hope this helps.

    Tom
  • Thanks this helped a lot.
Sign In or Register to comment.