Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8853433
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T13:39:04+00:00 2026-06-14T13:39:04+00:00

#include <stdio.h> #include <math.h> void getInput( int *metricUnit, int *englishUnit, int *metricNum, int *englishNum,

  • 0
#include <stdio.h>
#include <math.h>

void getInput( int *metricUnit, int *englishUnit, int *metricNum, int *englishNum, int *valueConvert, int convert);
int getMetricUnit(int *metricNum);
int getEnglishUnit (int *englishNum);
int getValueConvert(int convert, int *metricUnit);
double convertLiquid(int metricUnit, int englishUnit, int convert, double converted);
void printOutput(int metricUnit, int englishUnit, int convert, double converted);

int main (void)
{
//Declarations
int metricUnit;
int englishUnit;
int convert;
int metricNum;
int englishNum;
int valueConvert;
int converted;

//Statements
getInput(&metricUnit, &englishUnit, &metricNum, &englishNum, &valueConvert, convert);
convertLiquid(metricUnit, englishUnit, convert, converted);
printOutput(metricUnit, englishUnit, convert, converted);

return 0;
}

void getInput( int *metricUnit, int *englishUnit, int *metricNum, int *englishNum, int *valueConvert, int convert) //Function 0
{
*metricUnit = getMetricUnit(metricNum);
*englishUnit = getEnglishUnit(englishNum);
*valueConvert = getValueConvert(convert, metricUnit);
}

int getMetricUnit(int *metricNum)      //Subfunction 1 of getInput

{
printf("Metric Units (Input)\n");
printf("1 - Milliliters \n");
printf("2 - Centiliters \n");
printf("3 - Deciliters \n");
printf("4 - Liters \n");
printf("Enter the number of metric unit: ");
scanf("%d", metricNum);
printf("\n");

return *metricNum;
}

int getEnglishUnit (int *englishNum)    //Subfunction 2 of getInput

{
printf("English Units (Output) \n");
printf("1 - Fluid Ounce \n");
printf("2 - Cup \n");
printf("3 - Pint \n");
printf("4 - Quart \n");
printf("5 - Gallon \n");
printf("Enter the number of the English unit: ");
scanf("%d", englishNum);

return *englishNum;

} 

int getValueConvert(int convert, int *metricUnit)
{
switch (*metricUnit)
{
    case 1: printf("Enter the milliliter value to convert: ");
            scanf("%d", &convert); break;
    case 2: printf("Enter the centiliter value to convert: ");
            scanf("%d", &convert); break;
    case 3: printf("Enter the deciliter value to convert: ");
            scanf("%d", &convert); break;
    case 4: printf("Enter the liter value to convert: ");
            scanf("%d", &convert); break;
    default: printf("Enter the milliliter value to convert: ");
            scanf("%d", &convert); break;
}

if (convert > 0) return convert;
else return 0;
}

double convertLiquid(int metricUnit, int englishUnit, int convert, double converted)
{
double milliliter;
double centiliter;
double deciliter;
double liter;
double fluidOunce;
double cup;
double pint;
double quart;
double gallon;

    switch (metricUnit)
{
    case 1:  metricUnit = milliliter; convert = milliliter       ;break;
    case 2:  metricUnit = centiliter; convert = milliliter * 10  ;break;
    case 3:  metricUnit = deciliter ; convert = milliliter * 100 ;break;
    case 4:  metricUnit = liter     ; convert = milliliter * 1000;break;
    default: metricUnit = milliliter; convert = milliliter       ;break;
} //end swtich1
    fluidOunce = ((double)convert) * 29.537;

switch (englishUnit)
{
    case 1:  englishUnit = fluidOunce; converted = fluidOunce ; break;
    case 2:  englishUnit = cup;  converted = fluidOunce * 8 ; break;
    case 3:  englishUnit = pint;  converted = fluidOunce * 16; break;
    case 4:  englishUnit = quart;   converted = fluidOunce * 32; break;
    case 5:  englishUnit = gallon;   converted = fluidOunce * 128; break;
    default: englishUnit = fluidOunce; converted = fluidOunce     ; break;
}  //end switch2
return converted;
}

void printOutput(int metricUnit, int englishUnit, int convert, double converted)
{
switch (metricUnit)
{
    case 1: printf("%lf milliliter(s) = %lf  ", (double)convert);
    case 2: printf("%lf centiliter(s) = ", (double)convert);
    case 3: printf("%lf deciliter(s) = ", (double)convert);
    case 4: printf("%lf liter(s) = ", (double)convert);
    default: printf("%lf milliliter(s) = ", (double)convert);   

}
}


Im having the trouble with the printOutput function, 

this is the test run

Metric Units (Input)
1: Milliliter
2: Centiliter
3: Deciliter
4: Liter
Enter the number of the metric unit: 5

English Units (Output)
1: Fluid Ounce
2: Cup
3: Pint
4: Quart
5: Gallon
Enter the number of the English unit: 0
Enter the milliliter value to convert: 300
300.000 milliliter(s) = 10.144 fluid ounce(s)

I just cant figure out how to get the last line of this test run. the last line shows 2 variables which are milliliter and fluid ounce, how do i put 2 variables in 2 switch statements ? or how can i make the last line appear in the same way as the test run.

thank you in advance

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T13:39:05+00:00Added an answer on June 14, 2026 at 1:39 pm

    I am a little confused about the exact question you are asking but you can nest a switch within a switch.

    void printOutput(int metricUnit, int englishUnit, int convert, double converted)
    {
        switch (metricUnit)
        {
            case 1: printf("%lf milliliter(s) = ", (double)convert);
                    switch (englishUnit)
                    {
                        case 1: printf("%lf fluid ounce(s)\n", (double)converted); break;
                        case 2: printf("%lf cup(s)\n", (double)converted); break;
                        case 3: printf("%lf pint(s)\n", (double)converted); break;
                        case 4: printf("%lf quart(s)\n", (double)converted); break;
                        case 5: printf("%lf gallons(s)\n", (double)converted); break;
                    }
            break;
    
            case 2: printf("%lf centiliter(s) = ", (double)convert);
                    switch (englishUnit)
                    {
                        case 1: printf("%lf fluid ounce(s)\n", (double)converted); break;
                        case 2: printf("%lf cup(s)\n", (double)converted); break;
                        case 3: printf("%lf pint(s)\n", (double)converted); break;
                        case 4: printf("%lf quart(s)\n", (double)converted); break;
                        case 5: printf("%lf gallons(s)\n", (double)converted); break;
                    }
            break;
    
            case 3: printf("%lf deciliter(s) = ", (double)convert);
                    switch (englishUnit)
                    {
                        case 1: printf("%lf fluid ounce(s)\n", (double)converted); break;
                        case 2: printf("%lf cup(s)\n", (double)converted); break;
                        case 3: printf("%lf pint(s)\n", (double)converted); break;
                        case 4: printf("%lf quart(s)\n", (double)converted); break;
                        case 5: printf("%lf gallons(s)\n", (double)converted); break;
                    }
            break;
    
            case 4: printf("%lf liter(s) = ", (double)convert);
                    switch (englishUnit)
                    {
                        case 1: printf("%lf fluid ounce(s)\n", (double)converted); break;
                        case 2: printf("%lf cup(s)\n", (double)converted); break;
                        case 3: printf("%lf pint(s)\n", (double)converted); break;
                        case 4: printf("%lf quart(s)\n", (double)converted); break;
                        case 5: printf("%lf gallons(s)\n", (double)converted); break;
                    }
            break;
    
            default: printf("%lf milliliter(s) = ", (double)convert);
                    switch (englishUnit)
                    {
                        case 1: printf("%lf fluid ounce(s)\n", (double)converted); break;
                        case 2: printf("%lf cup(s)\n", (double)converted); break;
                        case 3: printf("%lf pint(s)\n", (double)converted); break;
                        case 4: printf("%lf quart(s)\n", (double)converted); break;
                        case 5: printf("%lf gallons(s)\n", (double)converted); break;
                    }
            break;
        }
    }
    

    But this method is a bit labor intensive if you could, I would change englishUnit and metricUnit to arrays so you can print the output with one single printf(). Of course you would have to rewrite pretty much all of your program.

    char metricUnit[20];
    char englishUnit[20];
    
    printf("%lf %s(s) = %lf %s(s)\n", (double)convert, metricUnit, (double)converted, enlgishUnit); 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

#include <stdio.h> #include <math.h> long int input; long int base, exponent; void convert(long int
#include <stdio.h> #include <math.h> void main() { int i, diff, sum = 0, num1
Below is my code: #include <stdio.h> #include <math.h> void main () { int my_data[4][500];
#include <stdio.h> #include <math.h> int main (void) { float inches; printf(Enter the number of
I have the following code: #include <stdio.h> #include <math.h> int main(void) { printf(%f\n, fmax(1.2,
#include <stdio.h> #include <math.h> #include <stdlib.h> int main(void) { char wunit[2]; // weight unit
#include stdafx.h #include stdio.h #include math.h #include stdlib.h void test (int a,int *b, int
#include<stdio.h> #include<math.h> int main(int argc, char **argv){ // read in the command-line argument double
#include <stdio.h> #include <stdlib.h> int main(void) { int x; int *in, *begin; in =
#include <stdio.h> void wrapperPrint(char* s) { printf(s); return; } int main() { wrapperPrint(Hello world\n);

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.