struct in c

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • haidarrrr
    New Member
    • Oct 2015
    • 18

    struct in c

    Hi !

    I'm trying to build a program that can convert polar to polar to cartesian using struct variables1 but here i came across a problem witch is when i scanf the values of (a&b) it telles me that i have to enter yet a another one !!

    the code is !

    Code:
    #pragma warning(disable:4996)
    #include<stdio.h>
    #include<stdlib.h>
    #include<math.h>
    void PolarTo_Cartesian(double r, double d, double *q, double *u);
    
    struct MyStruct
    {
    	double x;
    	double y;
    }; 
    
    int main(){
    
    	printf("enter ur cord\n");
    	
    	struct MyStruct a;
    	struct MyStruct b;
    
    	a.x; // puting value to x  
    	b.y;
    
       scanf("%lf\n", &(a.x));
       scanf("%lf\n", &(b.y));
    
        PolarTo_Cartesian(a.x, b.y, &(a.x), &(b.y)); // to store the address so i can change its value !!
       printf("the valus is (%lf,%lf)\n",a.x,b.y);
    
    	system ("pause");
    
    	return 0;
    }
    void PolarTo_Cartesian(double r, double d, double *q, double *u) {
    
    	*u = r*(sin(d));
    	*q = r*(cos(d));
    
    }
  • Clearner321
    New Member
    • Sep 2015
    • 22

    #2
    replace the scanf with this that is remove the newline.
    Code:
       scanf("%lf", &(a.x));
       scanf("%lf", &(b.y));

    Comment

    • haidarrrr
      New Member
      • Oct 2015
      • 18

      #3
      sorry dont really understand what u mean

      Comment

      Working...