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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T05:54:19+00:00 2026-06-05T05:54:19+00:00

I’ve documented the program specifications in the comment block located at the top. In

  • 0

I’ve documented the program specifications in the comment block located at the top. In the function displayNameByValue, I’m passing in an integer variable called passValue that stores the number of times the user’s name will be displayed to the console. I want to be able to account for user input error and validate for any input the user passes in that’s not represented by an integer. What’s the best possible solution to handle this situation?

Here’s my code :

/*******************************************************************************
 Concept:
         1.) Display the Programmer's Name
         2.) Display the Programmer's Name Again
         3.) Display the Programmer's Name X Times
         4.) Display a Triangle of an Entered Character
         5.) Exit the Program 
*******************************************************************************/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <limits.h>

char displayMenu();
void displayName(char *userName);
void displayNameAgain(char *userName);
int displayNameByValue(char *userName, int passValue);

char *userName = "Demetrius \n";

int main()
{
    char menuOption;
    int passValue = 0;

menuOption = displayMenu();
while(menuOption != 'E')
{
   switch(menuOption)
   {
     case 'A':
              displayName(userName);
              break;
     case 'B':
              displayNameAgain(userName);
              break;
     case 'C':
              displayNameByValue(userName, passValue);
              break;
     case 'D':
              // currently working @ the moment...
              break;
     default:
              printf("You've entered an invalid character entry! \n\n");
              break;
    }
              menuOption = displayMenu();
}

system("pause");
return 0;
}

char displayMenu()
{
char menuChoice;

printf("**********************************************************\n");
printf("A. Display the Programmer's Name                         *\n");
printf("B. Display the Programmer's Name Again                   *\n");
printf("C. Display the Programmer's Name X times                 *\n");
printf("D. Display a Triangle of an Entered Character            *\n");
printf("E. Exit the Program                                      *\n");
printf("**********************************************************\n\n");

printf("Enter a character that corresponds to the menu above :\n");
scanf("%s", &menuChoice);

menuChoice = toupper(menuChoice); // Assigns all menu submissions to uppercase 

return menuChoice;
}

void displayName(char *userName)
{
 printf("%s", userName);
}

void displayNameAgain(char *userName)
{
 printf("The programmer's name is : %s" , userName);
}

int displayNameByValue(char *userName, int passValue)
{
int index;

printf("Enter the number of times to display your name :");
scanf("%d", &passValue);


for(index = 0; index < passValue; index++)
{
          printf("%s\n", userName);
}

printf("Your name was displayed : %d times\n", index);

return passValue;
}
  • 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-05T05:54:20+00:00Added an answer on June 5, 2026 at 5:54 am

    Since the parameter int passValue is, well, an integer it will ALWAYS (by definition) be somewhere in the range INT_MIN to INT_MAX.

    If you are instead interested in making sure the value is in a narrower range (say at least 1 and less than 100), you could define constants in your program for the MIN_ACCEPTABLE and MAX_ACCEPTABLE values, and test like

    if (passValue < MIN_ACCEPTABLE || passValue > MAX_ACCEPTABLE)
    {
        // Report the error somehow
    }
    

    The function as written does not allow for “bad” (as in non-integer) input because the parameter is of type integer.

    If your intent is to convert a char * to an int, have a look at strtol.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I need a function that will clean a strings' special characters. I do NOT
I want to construct a data frame in an Rcpp function, but when I
I have just tried to save a simple *.rtf file with some websites and
I used javascript for loading a picture on my website depending on which small
I have a jquery bug and I've been looking for hours now, I can't
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but

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.