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 9230703
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T05:53:20+00:00 2026-06-18T05:53:20+00:00

I want to use a get choice function to let user choose a letter

  • 0

I want to use a get choice function to let user choose a letter from a menue, and i want to use this value to switch it in a float function…i know its only possible to use switch as type int, but will the value i will get is going to be float?

float calc(float number1, float number2)

{
int answer = get_choice();

switch (answer)
    {
        case 'a':
            answer = number1 + number2;
            break;
        case 's':
            answer = number1 - number2;
            break;
        case 'm':
            answer = number1 * number2;
            break;
        case 'd':
            answer = number1 / number2;
            break;
    }
return answer; }

char get_choice(void)

{
int choice;

printf("Enter the operation of your choice:\n");
printf("a. add        s. subtract\n");
printf("m. multiply   d. divide\n");
printf("q. quit\n");

while ((choice = getchar()) == 1 && choice != 'q')
{

    if (choice != 'a' || choice != 's' || choice != 'm' || choice != 'd')
    {
        printf("Enter the operation of your choice:\n");
        printf("a. add        s. subtract\n");
        printf("m. multiply   d. divide\n");
        printf("q. quit\n");
        continue;
    }


}
return choice; }
  • 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-18T05:53:21+00:00Added an answer on June 18, 2026 at 5:53 am
    float calc(float number1, float number2)
    
    { int choice = get_choice();
      float answer = 0.0;
    
      switch (choice)
    

    There is no need to reuse the variable. You can also switch a char variable directly.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to use this SQL query to get only the records between 8
I want to use the cpplint.py script to get coding style errors on the
I want to use LyricAPI hosted on Wikia to get lyrics of songs. But
I want to use magic function __set() and __get() for storing SQL data inside
We want to use Automapper in commercial application (.NET 3.5). To get the clearance
i want to use shopping cart in my portal. can i get shopping cart
How can I get the current selected row for UIPicker? I want to use
How can I get all differences, not just one? I want to use the
I want to install mysql in my Ubuntu 11.10. I use sudo apt-get install
I want to get XJC to use the javaType tag in a complexType when

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.