Question

NEED CODE HELPS WITH C PROGRAMMING. ISSUES EXPLAINED IN BOLD. COMPARING TWO LETTERS AND CALLING A...

NEED CODE

HELPS WITH C PROGRAMMING. ISSUES EXPLAINED IN BOLD.

COMPARING TWO LETTERS AND CALLING A FUNCTION.  

Problem are explained in bold
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define pi 3.1415

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-\n");
void (*f[4]) (double) = {Circumference, Area, VolSphere, AllCalc};


int pick;
float r, r2;
char choice;

//suppose user want to enter radius = 10;

printf("\nWhat 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( "\nPick a number according to what you want to calculate:\n"
"0 = Circumference | 1 = Area | 2 = Volume | 3 = All Calc | 4 = End Program: ");
scanf( "%d", &pick);


while ( pick >= 0 && pick < 4 ) {
(*f[pick])(r);

printf( "\nPick a number according to what you want to calculate\n"
"0 = Circumference | 1 = Area | 2 = Volume | 3 = All calculations | 4 = End program: ");
scanf ( "%d", &pick);
}
}

void Circumference (double n)
{
puts("\n\n-CIRCUMFERENCE-");
printf( "\nThe radius is %.2f\n" , n);
printf( "The circumference of the circle is: %.2f\n" , 2 * pi * n);
}

void Area (double n)
{
puts("\n\n-AREA-");
printf( "\nThe radius is %.2f\n" , n);
printf( "The area of the circle is: %.2f\n" , pi * n * n);

}

void VolSphere (double n)
{

puts("\n\n-VOLUME-");
printf( "\nThe radius is %.2f\n" , n);
printf( "The volume of the circle is: %.2f\n" ,(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:........

}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

/******************************************************************************

Online C Compiler.
Code, Compile, Run and Debug C program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

//gcc 5.4.0
/******************************************************************************

Online C Compiler.
Code, Compile, Run and Debug C program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

/******************************************************************************

Online C Compiler.
Code, Compile, Run and Debug C program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/
/******************************************************************************

Online C Compiler.
Code, Compile, Run and Debug C program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define pi 3.1415

void Area (double n);
void VolSphere (double n);
void Circumference (double n);
void AllCalc (double n); // 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-\n");
void (*f[4]) (double) = {Circumference, Area, VolSphere, AllCalc};


int pick;
double r, r2;
char choice;

//suppose user want to enter radius = 10;

printf("\nWhat 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("%c %lf", &choice, &r2); //i am scanning letter and number to compare with d D r and R


if ((choice == 'd') || (choice == '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( "\nPick a number according to what you want to calculate:\n"
"0 = Circumference | 1 = Area | 2 = Volume | 3 = All Calc | 4 = End Program: ");
scanf( "%d", &pick);


while ( pick >= 0 && pick < 4 ) {
(*f[pick])(r);

printf( "\nPick a number according to what you want to calculate\n"
"0 = Circumference | 1 = Area | 2 = Volume | 3 = All calculations | 4 = End program: ");
scanf ( "%d", &pick);
}
}

void Circumference (double n)
{
puts("\n\n-CIRCUMFERENCE-");
printf( "\nThe radius is %.2f\n" , n);
printf( "The circumference of the circle is: %.2f\n" , 2 * pi * n);
}

void Area (double n)
{
puts("\n\n-AREA-");
printf( "\nThe radius is %.2f\n" , n);
printf( "The area of the circle is: %.2f\n" , pi * n * n);

}

void VolSphere (double n)
{

puts("\n\n-VOLUME-");
printf( "\nThe radius is %.2f\n" , n);
printf( "The volume of the circle is: %.2f\n" ,(4 * pi * n * n * n)/3);
}

void AllCalc (double n) //Inside of this function i need to call all 3 (Volume, area, circumference) to make a summary of the calculations. Preferably using pointers
{
void (*f[]) (double) = {Circumference, Area, VolSphere};
for(int i=0;i<3;i++)
(*f[i])(n);

}

**************************************************

Since AllCalc() function calls the volume, area, circumference functions to make summary of calculations, it can't print the value as those functions are returning void(nothing) and they are displaying the result in their function body itself.

Output:

---------

-Calculating Circle Circumference, Circle Area or Sphere Volume-                                                             

                                                                                                                             

                                                                                                                             

What is the radius of the circle?: d 20                                                                                      

                                                                                                                             

Pick a number according to what you want to calculate:                                                                       

0 = Circumference | 1 = Area | 2 = Volume | 3 = All Calc | 4 = End Program: 2                                                

                                                                                                                             

                                                                                                                             

-VOLUME-                                                                                                                     

                                                                                                                             

The radius is 10.00                                                                                                          

The volume of the circle is: 4188.67                                                                                         

                                                                                                                             

Pick a number according to what you want to calculate                                                                        

0 = Circumference | 1 = Area | 2 = Volume | 3 = All calculations | 4 = End program: 3

-CIRCUMFERENCE-                                                                                                              

                                                                                                                             

The radius is 10.00                                                                                                          

The circumference of the circle is: 62.83                                                                                    

                                                                                                                             

                                                                                                                             

-AREA-                                                                                                                       

                                                                                                                             

The radius is 10.00                                                                                                          

The area of the circle is: 314.15                                                                                            

                                                                                                                             

                                                                                                                             

-VOLUME-                                                                                                                     

                                                                                                                             

The radius is 10.00                                                                                                          

The volume of the circle is: 4188.67                                                                                         

                                                                                                                             

Pick a number according to what you want to calculate

0 = Circumference | 1 = Area | 2 = Volume | 3 = All calculations | 4 = End program: 4                                        

  

Add a comment
Know the answer?
Add Answer to:
NEED CODE HELPS WITH C PROGRAMMING. ISSUES EXPLAINED IN BOLD. COMPARING TWO LETTERS AND CALLING A...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • I wrote a program which computes the area and perimeter of a square, circle, or rectangle. As you will see in my main function, there is a for loop in which the user is supposed to be able repeat the...

    I wrote a program which computes the area and perimeter of a square, circle, or rectangle. As you will see in my main function, there is a for loop in which the user is supposed to be able repeat the program until they enter "q" to quit. However, my program runs through one time, the prompt appears again, but then it terminates before the user is allowed to respond to the prompt again. I'm not able to debug why this...

  • Note- can you rewrite the code in C++ if there is any existing code. Can you...

    Note- can you rewrite the code in C++ if there is any existing code. Can you not use arrow -> operator. Write a circle class that has the following member variables: • radius: a double • pi: a double initialized with the value 3.14159 The class should have the following member functions: • Default Constructor. A default constructor that sets radius to 0.0. • Constructor. Accepts the radius of the circle as an argument . • setRadius. A mutator function...

  • So I have a question in regards to my program. I'm learning to program in C...

    So I have a question in regards to my program. I'm learning to program in C and I was curious about the use of functions. We don't get into them in this class but I wanted to see how they work. Here is my program and I would like to create a function for each of my menu options. I created a function to display and read the menu and the option that is entered, but I would like to...

  • Need help with this C program? I cannot get it to compile. I have to use...

    Need help with this C program? I cannot get it to compile. I have to use Microsoft Studio compiler for my course. It's a word game style program and I can't figure out where the issue is. \* Program *\ // Michael Paul Laessig, 07 / 17 / 2019. /*COP2220 Second Large Program (LargeProg2.c).*/ #define _CRT_SECURE_NO_DEPRECATE //Include the following libraries in the preprocessor directives: stdio.h, string.h, ctype.h #include <stdio.h> /*printf, scanf definitions*/ #include <string.h> /*stings definitions*/ #include <ctype.h> /*toupper, tolower...

  • Identify the errors in this C program (struct - calculating volume, area of cylinder). Explain. #include...

    Identify the errors in this C program (struct - calculating volume, area of cylinder). Explain. #include <stdio.h> #define PI 3.14 typedef struct cylinder{    float r,h;    float areacircle=2*PI*r;    float areacylinder;    float volumecylinder;    areacylinder=2*PI*r*h+2*PI*r*r;    volumecylinder=PI*r*r*h; }; int main() {    float start,numcyls;    printf("How many cylinders do you want? Enter a positive integer.\n");    scanf("%f",&numcyls);    if(numcyls<1||ceilf(numcyls)!=numcyls)    while()    {printf("The number you have entered is not a positive integer. Please try again.\n");        printf("Remember,...

  • Please, I need help, I cannot figure out how to scan variables in to the function...

    Please, I need help, I cannot figure out how to scan variables in to the function prototypes! ******This is what the program should look like as it runs but I cannot figure out how to successfully build the code to do such.****** My code: #define _CRT_SECURE_NO_WARNINGS #include <stdio.h> #include <math.h> #include <conio.h> float computeSeriesResistance(float R1, float R2, float R3); float computeParallelResistance(float R1, float R2, float R3); float computeVoltage(int current, float resistance); void getInputR(float R1, float R2, float R3); void getInputCandR(int...

  • modify sample code from example two to calculate the surface area and volume of a sphere...

    modify sample code from example two to calculate the surface area and volume of a sphere givin the radius int main() Example 2 Introduction to structures and passing the structure variables as arguments into functions. 1. A structure is created with circle related variables. 2. Two functions are created related to circle calculations. 3. This example passes structure variables from the main function to the message Circle function 4. The message Circle function converts the structure variables into regular double...

  • C++ HELP I need help with this program. I have done and compiled this program in...

    C++ HELP I need help with this program. I have done and compiled this program in a single file called bill.cpp. It works fine. I am using printf and scanf. Instead of printf and scanf use cin and cout to make the program run. after this please split this program in three files 1. bill.h = contains the class program with methods and variables eg of class file class bill { } 2. bill.cpp = contains the functions from class...

  • In C++ Amanda and Tyler opened a business that specializes in shipping liquids, such as milk,...

    In C++ Amanda and Tyler opened a business that specializes in shipping liquids, such as milk, juice, and water, in cylindrical containers. The shipping charges depend on the amount of the liquid in the container. (For simplicity, you may assume that the container is filled to the top.) They also provide the option to paint the outside of the container for a reasonable amount. Write a program that does the following: Prompts the user to input the dimensions (in feet)...

  • C program help: Write a C program that uses three functions to perform the following tasks:...

    C program help: Write a C program that uses three functions to perform the following tasks: – The first function should read the price of an item sold at a grocery store together with the quantity from the user and return all the values to main(). example: #include void getInput(int *pNum1, int *pNum2); // note: *pNum1 & *pNum2 are pointers to ints int main () {    int numDucks,numCats;    getInput(&numDucks, &numCats); // passing addresses of num1 & num2 to...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT