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

  Heapsort executes in worst-case

For each of the following, indicate whether the statement is true or false, and explainwhy this is the case (you do not need to derive the correct asymptotic complexityyourself, but no marks will be awarded for an answer with no explanation).

  Understanding access control is a critical part of it secure

Understanding access control is a critical part of IT security. There are many factors to consider when choosing the "right" solution for your particular situation. Demonstrate your knowledge of access controls by briefly describing two of them..

  How does new media differ from traditional media

How does new media differ from traditional media? What are the advantages and disadvantages of each? Consider at least one type from each group and discuss those types specifically.

  Tabulate the minimum sample size needed

The half-width B desired could be anywhere from 2 to 7. Tabulate the minimum sample size needed for the given ranges of sigma and B.

  Create a japplet that contains a jlabel and jbutton.

Create a JApplet that contains a JLabel and JButton. You'll create a JButton that will automatically change font typeface, style, and size when clicked by the user. Change the font typeface, style, and size on the JLabel.

  What is the sum of the sizes of all the baskets

Suppose there are 100 items, numbered 1 to 100, and also 100 baskets, also numbered 1 to 100. Item i is in basket b if and only if b divides i with no remainder. For example, basket 12 consists of items

  Android mobile application development

You are a mobile application developer working for Mick Jagger who owns Wild Horses Incorporated (WHI).  Mick's company is just getting started with Android mobile application development. Mick wants to make sure that his developers understand and..

  Combinational subcircuits for the inputs

Then modify the combinational subcircuits for the inputs to the flip-flops and the outputs with the appropriate gates of a Moore sequence detector.

  Write a program to measure latency of communication

If you have access to an SMP and a cluster, write a program to measure latency of communication and bandwidth of communication between processors, as was plotted in Figure F.32 on page F-80.

  Economic realities of healthcare delivery

Why do traditional economic theories of supply and demand don't adequately address the economic realities of healthcare delivery in the United States?

  What features would you look for on the switches

What features would you look for on the switches you purchase for design and explain why you would want each feature. Do you need to include any other devices in this design?

  Effective scanning and enumeration approach

The steps in an effective scanning and enumeration approach. The potential resources available to support scanning and enumeration activities.

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