ANSWERS: 2
  • Think recursion.
  • int value = 0; char input; while(input != 'n') { input = getc(); /* Might need to be called twice */ value += input-48; /*because of problems with getc() */ } I'm not sure if this is what you meant, but this will take keyboard input until a newline character is encountered. Each new character entered is added to the total (value). It is meant to only receive numbers such as 0-9, but technically ; and : could be used as well (10 and 11). Essentially just adds the character code -48. You could easily add error checking for other values, such as: if(input > 47 && < 59) before the line that adds the new value.

Copyright 2023, Wired Ivy, LLC

Answerbag | Terms of Service | Privacy Policy