Question
NEED CODE HELPS WITH C PROGRAMMING. ISSUES EXPLAINED IN BOLD. COMPARING TWO LETTERS AND CALLING A FUNCTION. Problem are explained in bold #include #include #include
NEED CODE
HELPS WITH C PROGRAMMING. ISSUES EXPLAINED IN BOLD.
COMPARING TWO LETTERS AND CALLING A FUNCTION.
Problem are explained in bold #include
void Area (double n); void VolSphere (double n); void Circumference (double n); void AllCalc (); // i dont know if the declaration of the function is correct AllCalc = AllCalculations
//function main begins program execution int main (void) { puts("-Calculating Circle Circumference, Circle Area or Sphere Volume- "); void (*f[4]) (double) = {Circumference, Area, VolSphere, AllCalc};
int pick; float r, r2; char choice;
//suppose user want to enter radius = 10;
printf(" What is the radius of the circle?: "); //the user can either enter: r 10 or R 10 (for the radius) or d 10 D10 (for the diameter) scanf("%s%f", choice, &r2); //i am scanning letter and number to compare with d D r and R
if (choice == 'd' || 'D') // right here i am comparing choice with d or D. If user entered d 10 then i want to devide radius by 2. If not, remains the same r = r2/2; //for some reason the program is not running i tried "strcmp(choice, "d")" but it didnt work either. I dont know if it is if statement or i am going the wrong way
else { r = r2;
}
printf( " Pick a number according to what you want to calculate: " "0 = Circumference | 1 = Area | 2 = Volume | 3 = All Calc | 4 = End Program: "); scanf( "%d", &pick);
while ( pick >= 0 && pick < 4 ) { (*f[pick])(r);
printf( " Pick a number according to what you want to calculate " "0 = Circumference | 1 = Area | 2 = Volume | 3 = All calculations | 4 = End program: "); scanf ( "%d", &pick); } }
void Circumference (double n) { puts(" -CIRCUMFERENCE-"); printf( " The radius is %.2f " , n); printf( "The circumference of the circle is: %.2f " , 2 * pi * n); }
void Area (double n) { puts(" -AREA-"); printf( " The radius is %.2f " , n); printf( "The area of the circle is: %.2f " , pi * n * n);
}
void VolSphere (double n) {
puts(" -VOLUME-"); printf( " The radius is %.2f " , n); printf( "The volume of the circle is: %.2f " ,(4 * pi * n * n * n)/3); }
void AllCalc () //Inside of this function i need to call all 3 (Volume, area, circumference) to make a summary of the calculations. Preferably using pointers
{
//here the output should be something like
Circumference is: ....
Volume is:......
Area is:........
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started