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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T09:05:53+00:00 2026-06-17T09:05:53+00:00

I have a class assignment in C to make a simple calculator that performs

  • 0

I have a class assignment in C to make a simple calculator that performs three calculations. I haven’t completed all of the functions yet but I am having a problem with my calcMenu function. When the function is called the program runs through all of the if else statements and unknown to me, performs only the else statement which is error checking. Than the function is run again which is intended but this time it does not run through all of the if else statements and allows the user to make a choice. I know I have done something really stupid but have been racking my brain for the last hour. If anyone has any pitty for me, than please point me in the right direction. I know all the system calls will Irk some but this is a basic class and our instructor has told us to use them.

Thanks in advance,

Mike

#include <stdlib.h>
#include <stdio.h>
#include <ctype.h>
#define pause system ("pause")
#define cls system ("cls")

//Prototype calculate functions here
void evenOrOdd(int userNumber);
void squareNum(int userNumber);
void cubeNum(int userNumber);
void calcMenu(int userNumber);

void main() {
    //Declare local variables here
int userNumber = 0;
printf("\t\t\tThe amazing three function caluculator\n\n\n");
printf("Please enter a whole number that you would like to calculate\n");
scanf("%d", &userNumber);


calcMenu(userNumber);
}



void calcMenu(int userNumber)
{
char calculateOption;
printf("\nWhat calculation would you like to perform with your number?\n\n");
printf("Press A.) to check if your number is even or odd.\n\n");
printf("Press B.) to calculate the square of your number.\n\n");
printf("Press C.) to calculate the cube of your number.\n\n");
printf("press D.) to exit the program.\n");
scanf("%c", &calculateOption);
calculateOption = toupper (calculateOption);



if (calculateOption == 'A')
{
    evenOrOdd(userNumber);
}
else if (calculateOption == 'B')
{
    squareNum(userNumber);
}
else if (calculateOption == 'C')
{
    cubeNum(userNumber);
}
else if (calculateOption == 'D')
{
    system("cls");
    printf("Thank You for using my amazing calculator.\n\n");
    system ("pause");
    system ("exit");
}
else
{
    printf("Please enter a valid choice");
    calcMenu(userNumber);
}


}


void evenOrOdd(int userNumber) {
userNumber = userNumber %2;
if (userNumber == 0)
{
    printf("Your number is even. \n");
}
else
{
    printf("Your number is odd. \n");
}

}
void squareNum(int userNumber) {

}
void cubeNum(int userNumber){

}
  • 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-17T09:05:54+00:00Added an answer on June 17, 2026 at 9:05 am

    First of all, You can condense all those printf statements into one function to save the extra calls.

    Next, you should probably indent your functions, I can’t tell where one begins and another ends at a glance.

    Third, don’t use system("pause"), use getchar().

    Fourth, this is optional, you might want to turn those if statements into a switch statement.

    Now, on to your question. First of all, instead of using scanf("%c", &calculateOption), just use getchar() here too. In this case, I would write calcMenu() as this:

    int calcMenu(int userNumber){
        printf("\nWhat calculation would you like to perform with your number?\n\n\
        Press A.) to check if your number is even or odd.\n\n\
        Press B.) to calculate the square of your number.\n\n\
        Press C.) to calculate the cube of your number.\n\n\
        Press D.) to exit the program.\n");
    
        switch(toupper(getchar())){
            case 'A':
                evenOrOdd(userNumber);
                break;
            case 'B':
                squareNum(userNumber);
                break;
            case 'C':
                cubeNum(userNumber);
                break;
            case 'D':
                system("cls"); //this is bad, really.
                printf("Thank You for using my amazing calculator.\n\n");
                getchar();
                return 0;
            default:
                printf("Please enter a valid choice: ");
                calcMenu(userNumber);
                break;
        }
    }
    

    Also, main should always return a value. void main is bad practice.

    Disclaimer: The code isn’t tested, you shouldn’t copy/paste it anyways. I also don’t know if you’re being forced to use some things or not…

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

Sidebar

Related Questions

I have an assignment in my java class to make a very simple phishing
I have an assignment in my Operating Systems class to make a simple pseudo-stack
Can I optimize the class assignment here at all? I have to do this
I have completed the assignment (yes it is for a programming class), but I
I have an assignment and I need to make my own (simple) generic linked
In my assignment i have to make a simple version of Craps, for some
I have to do an assignment for my class and it says not to
For my second programming assignment in my Java class, we have to create a
As part of the last assignment in a beginner python programing class, I have
I have class that extend FragmentActivity in it I add fragment to layout as

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.