Computer Science Canada

program help

Author:  Geminias [ Tue Oct 04, 2005 8:13 pm ]
Post subject:  program help

hey, i'm a noob having some trouble with this program. Won't compile and i don't understand the compiler's hints. If anyone could give me some pointers on what is wrong please do so.



Syntax = C++
code:
#include <iostream>
#include <windows.h>
#include <math.h>
using namespace std;

float quadrant1y (float s, float t)
{
      float yaxis;

      yaxis = sin*s*t;
     
      return (yaxis);
}
 
float quadrant1x (float x, float y)
{
      float xaxis;

     
      xaxis = cos*x*y;

     
      return (xaxis);
}

int main ()
{

cout << "This program will resolve vectors into their components.\n";
cout << "Just follow the instructions. /n";
sleep (1000);
cout << "Enter the displacement in km";
cin >> displacement;
cout << "input the angle.";
cin >> angle;

if (0 <= angle <=90)
{
   quadrant1x (angle, displacement)
   quadrant1y (angle, displacement)
}

   cout << "the x axis is: " << quadrant1x << endl;
   cout << "the y axis is: " << quadrant2y << endl;
   
     return 0;
}



Author:  wtd [ Tue Oct 04, 2005 8:27 pm ]
Post subject: 

Well, there are many things wrong with your code, but one stands out in particular. "sin" is a function. Why aren't you calling it as such?

code:
sin*s*t

Author:  Geminias [ Tue Oct 04, 2005 8:28 pm ]
Post subject: 

i thought it was more like an operand Rolling Eyes

Author:  wtd [ Tue Oct 04, 2005 8:30 pm ]
Post subject: 

Also, where is "displacement" declared?

code:
cin >> displacement;

Author:  md [ Tue Oct 04, 2005 8:42 pm ]
Post subject: 

I was going to write a nice big thing here but sicne I seem to have been beaten to it while writing it I'll just post some fixed code so you can see it working:

c++:


#include <iostream>
#include <windows.h>
#include <math.h>

float quadrant1y (float s, float t)
{
      return sin(s*t);
}
 
float quadrant1x (float x, float y)
{
      return cos(x*y);
}

int main ()
{

float displacement;
float angle;

cout << "This program will resolve vectors into their components.\n";
cout << "Just follow the instructions. /n";
sleep (1000);
cout << "Enter the displacement in km";
cin >> displacement;
cout << "input the angle.";
cin >> angle;

if (0 <= angle <=90)
{
   cout << "the x axis is: " << quadrant1x(angle, displacement) << endl;
   cout << "the y axis is: " << quadrant2y(angle, displacement) << endl;
}

return 0;
}


Author:  Geminias [ Tue Oct 04, 2005 9:29 pm ]
Post subject: 

thanks guys. But one question.

you put "sin(s*t)"

is that the same as "sin(s) * (t)" ?

because it is not the same thing on a calculator.

Author:  wtd [ Tue Oct 04, 2005 9:48 pm ]
Post subject: 

No.

You have the function name, then parentheses. Inside the parentheses are any argument(s) to the function.

In this case the argument is "s * t".

Author:  [Gandalf] [ Tue Oct 04, 2005 10:26 pm ]
Post subject: 

Laughing Nice new sig, wtd

You were also missing some ';''s from the end of some lines, try to check that first if you get some errors (which should easily tell you that this is the problem).


: