I tried to troubleshoot this and couldn't find the exact problem as to why I'm getting this error(error: invalid type argument of unary ‘*’ (have ‘double’) *outerD_P = outerD;) . I tried making innerD_P and outerD_P a ** but that didn't work. I'm sorry if it's a simple fix I'm still learning C. Thank you for the help
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
// PI is the ratio of diameter to the circumfrence of a circle
#define PI 3.1415
int main(int argc, const char *argv[])
{
double weight, volume, batchWeight, innerA, outerA, area;
double innerD, outerD, density, thickness;
double* volume_P, density_P, innerA_P, outerA_P, area_P, thickness_P;
double* innerD_P, outerD_P;
int quantity;
int* quantity_P;
//variables that point to the corresponding command line arguments beleow:
innerD = atof(argv[1]);
outerD = atof(argv[2]);
thickness = atof(argv[3]);
density = atof(argv[4]);
quantity = atoi(argv[5]);
//Not allowing the user to enter a 0 for quantity must have atleast ONE washer
if(quantity < 1)
{
printf("Quantity can not be less than 1! Try again\n.");
return 0;
}
//setting the pointer equal to the command line input
*innerD_P = innerD;
*outerD_P = outerD;
innerA = PI*pow(*innerD_P/2, 2);
outerA = PI*pow(*outerD_P/2, 2);
CodePudding user response:
double* volume_P, density_P, innerA_P, outerA_P, area_P, thickness_P;
double* innerD_P, outerD_P;
In those lines the *
only binds to the next variable. It means that the above is actually declaring only the first variable on each line as a pointer and all the rest are double
.
Change to:
double *volume_P, *density_P, *innerA_P, *outerA_P, *area_P, *thickness_P;
double *innerD_P, *outerD_P;