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

  Improve the profitability of credit sales

You have been asked to assess the expected financial impact of each of the following proposals to improve the profitability of credit sales made by your company. Each proposal is independent of the other. Answer all questions. Showing your work..

  How is checkpointing done in aries

Give an example that illustrates how the paradigm of repeating history and the use of CLRs allow ARIES to support locks of finer granularity than a page.

  Describe the capability maturity mode

Describe the Capability Maturity Mode. At what level is it appropriate to introduce CASE environments and why ?

  What is the smallest possible size (in bytes) for the frame

Suppose you have a system with an 8 inch by 10 inch video screen that can display 100 pixels per inch. If a color lookup table with 64 positions is used with this system what is the smallest possible size (in bytes) for the frame buffer?

  What is the geometric center frequency

A band-pass filter has a lower cutoff frequency of 100 Hz and an upper cut-off frequency of 144 Hz. What is the geometric center frequency? (Points : 3) 120 Hz 130 Hz 134.5 Hz 140 Hz

  Use of type of software

If she replies to John's email, within seconds you will again receive a copy of what she sent to John. Describe two scenarios (other than those described here) for the use of this type of software: one in which the use would be ethical and one in ..

  Convicted of criminal computer use for any it position

What are your thoughts? What are the risks? Would you hire someone who had been convicted of criminal computer use for any IT position? Why or why not?

  How does a diesel engine differ from a gasoline engine

For a specified compression ratio, is a diesel or gasoline engine more efficient?

  Draw an object diagram

Note, in particular, that the filter variable in make Menu Bar has been declared as final, as discussed in Section 11.4.8. Make sure that you understand why this is necessary.

  Show how to solve the datalog query ancestor(aa,x)

Show the same query by computing only the changes in the ancestor relation and using that in rule 2 each time. [This question is derived from Bancilhon and Ramakrishnan (1986).]

  Significant factors a restaurant owner

Food Purchasing" Please respond to the following: Inventory the most significant factors a restaurant owner should consider when selecting food to purchase.

  Numbers as 4-bit words in 2''s complement form

Q. Assume the following numbers are represented as 4-bit words in 2's complement form. Perform the following operations and identify, in each case, whether or not an overflow occurs

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