There are a variety of loop constructs. Which to use depends upon a number of factors. In your case, a do {...} while (condition) block would be a reasonable approach. Unfortunately, your control condition statement at the end is bogus. The variable n has not been set, it is a different type than the Answer variable, and you are using an assignment operator instead of a comparison. So change the line
} while ( Answer = n );
to
} while ( Answer == 'n' || Answer == 'N' );
One last issue, is that after you ask the question "Do you want to do it again? (y/n)" you don't take input from the user, so the conditional clause at the end of the loop will not be properly set, at least as per your apparent intent... :-)
rubberman
Posting Maven
2,572 posts since Mar 2010
Reputation Points: 365
Solved Threads: 306
Skill Endorsements: 52
Question Answered as of 1 Year Ago by
rubberman Re: while (Answer == 'y' || Answer == 'Y') vs. while (Answer == 'n' || Answer == 'N') - that was a bit of a trick to see if you would come up with the correct answer... :-) Good start. As cherrymae.calma said, there are generally 3 types of loop constructs. You have used the do {} while (condition); loop. There are also for (start-condition, test-condition, next-step) and while (condition) {} loops. There is a fourth one, that should cause you to fail a project - a label + goto statement. It is rare for this fourth kind to be needed, though I have seen some kernel and driver code where it may have been appropriate due to behavior of volatile data and hardware event handling. With luck, you will never have to use it. In 30+ years of C and C++ development, I have possibly needed to use the label+goto twice under these conditions (kernel and/or hardware driver support), and the last time was over 20 years ago when developing TCP/IP driver code for a hard real-time operating system.
rubberman
Posting Maven
2,572 posts since Mar 2010
Reputation Points: 365
Solved Threads: 306
Skill Endorsements: 52