Depending on how many characters are entered

Assignment Help Basic Computer Science
Reference no: EM132200826

Below is a function that has a user enter (y)es or (n)o. And give an error and make them re-enter if anything other than 'y', 'Y', 'n', or 'N' is entered. It gives the error correctly if a single character is entered, but will print out multiple error messages at once if 3 or more characters are typed in and I don't understand why. My code is posted below.

int yes(void)

{

   char entry = '';

   char newLine = '';

   int result = 0;

   while ((entry != 'y' && entry != 'Y' && entry != 'n' && entry != 'N') || newLine != ' ')

      scanf("%c%c", &entry, &newLine);

      if ((entry != 'y' && entry != 'Y' && entry != 'n' && entry != 'N') || newLine != ' ')

      {

         printf("*** INVALID ENTRY *** <Only (Y)es or (N)o are acceptable>: ")

      }

      else if (entry == 'y' || entry == 'Y')

      {

         result = 1;

      }

   }

   return result;

}

Below is an example of the output that I'm receiving:

                         Do you want to enter a middle initial(s)? (y or n): f

                         *** INVALID ENTRY *** <Only (Y)es or (N)o are acceptable>: f

                         *** INVALID ENTRY *** <Only (Y)es or (N)o are acceptable>: f

                         *** INVALID ENTRY *** <Only (Y)es or (N)o are acceptable>: fff

                         *** INVALID ENTRY *** <Only (Y)es or (N)o are acceptable>:

                         *** INVALID ENTRY *** <Only (Y)es or (N)o are acceptable>: fffff

                         *** INVALID ENTRY *** <Only (Y)es or (N)o are acceptable>:

                         *** INVALID ENTRY *** <Only (Y)es or (N)o are acceptable>:

                         *** INVALID ENTRY *** <Only (Y)es or (N)o are acceptable>:

Depending on how many characters are entered seems to determine how many extra errors are printed.

Reference no: EM132200826

Questions Cloud

What is the difference compared to the small open economy : Explain in words the determination of rw in the case of two large economies. What is the basic difference compared to the small open economy?
Virtualized and cloud environment : Explain various security concerns and measures in the virtualized and cloud environment.
Give the running time of your program : Write a Java program called reverseQueue which takes as argument a queue and modifies it to have the content reversed.
By what percentage does real gdp change : Using the prices for 2009 as the set of common prices, what is real GDP in 2009 and in 2010? By what percentage does real GDP change from 2009 to 2010?
Depending on how many characters are entered : Depending on how many characters are entered seems to determine how many extra errors are printed.
Which contains the following elements : Given a stack s which contains the following elements: (2, 4, 6, 8, 10, 12 14) where 2 is at the bottom of the stack and 14 is at the top
What is the giant pool of money : To hear a synopsis of the 2008-09 credit crisis. Listen to the radio show This American Life entitled "The Giant Pool of Money" on May 9, 2008 (#355).
Draw a market area diagram showing the market area : In one hour, people can make one horseshoe or one bushel of vegetables. There is a blacksmith forge where a worker can make five horseshoes or one bushel.
What are your expectations for the quantity of coal : Researchers at Penn State have developed the means to produce high quality liquid fuels from coal, and are working on scaling up the process to produce.

Reviews

Write a Review

Basic Computer Science Questions & Answers

  Key utilities in operating system software

What are the key utilities in operating system software that allows users to customize their desktop and keep their PC maintained and optimized?

  Formulate the equation for concentration

(a) Formulate the equation for concentration of a moving substance. (b) Show that this is equal to the rate of change of quantity with respect to volume.

  Which kinds of computing and information systems

For which kinds of computing and information systems do users really need to care about underlying technologies -- which is what an operating system is? Which kinds of users ought to pay more attention to how well a variety of devices and application..

  How code an interactive hangman game using string method

How do you code an interactive hangman game using the string method

  What is the syntax of the inheritance method

What is the syntax of the Inheritance method to extending a base class in C++

  What is the sequencing of the respective points

What is the sequencing of the respective points

  What are some common troubleshooting steps

What are some common troubleshooting steps? What is the boot process of a typical computer?

  Advising about a software purchase

Your local art museum recently purchased a quad-core computer with 16 GB of RAM. The curator read an article about an art collection inventory system software package that could go on the new computer. You have a long experience with end users has..

  Explain the schema and global catalog

Explain the schema and global catalog. Outline the creation of user groups, organizational units, and security groups for all company departments.

  Write a function named location_of_largest

then the function should return the integer 2 as its value. If there is more than one cell containing the largest of the values in the array, then the function should return the smallest of the subscripts of the cells containing the largest values..

  Compare and contrast the application of it

Determine how information systems have allowed police departments that implement tools such as COMPSTAT to respond to crime faster. Apply the strengths, weaknesses, opportunities, and threats analysis (SWOT analysis) on behalf of police department..

  Develop this as a function of x

That is, what is the value for X when an exhaustive read of the file is more efficient than random X reads? Develop this as a function of X.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd