<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>KirkHings.com &#187; academic challenge</title>
	<atom:link href="http://kirkhings.com/tag/academic-challenge/feed/" rel="self" type="application/rss+xml" />
	<link>http://kirkhings.com</link>
	<description>The '-berger' part trips up so many folks that I sometimes simplify my name for you. Yes, just for you.</description>
	<lastBuildDate>Sat, 13 Jun 2009 18:35:59 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=abc</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Math Tutor Enhanced</title>
		<link>http://kirkhings.com/code/c/math-tutor-enhanced/417/</link>
		<comments>http://kirkhings.com/code/c/math-tutor-enhanced/417/#comments</comments>
		<pubDate>Tue, 09 Jun 2009 04:06:59 +0000</pubDate>
		<dc:creator>Kirk</dc:creator>
				<category><![CDATA[C++]]></category>
		<category><![CDATA[academic challenge]]></category>

		<guid isPermaLink="false">http://kirkhings.com/?p=417</guid>
		<description><![CDATA[ photo credit: foundphotoslj
4.9: This is a modification of Chapter 3&#8217;s Problem 15, which was:
Write a program that can be used as a math tutor for a young student. The program should display two random numbers to be added, such as 

   247
+ 129
------

The program should then pause while the student works on [...]


Related posts:<ul><li><a href='http://kirkhings.com/code/c/math-tutor/331/' rel='bookmark' title='Permanent Link: Math Tutor'>Math Tutor</a> <small> photo credit: *Zara This programming challenge is from an...</small></li>
<li><a href='http://kirkhings.com/code/c/saving-numbers-to-a-file/348/' rel='bookmark' title='Permanent Link: Saving Numbers to a File'>Saving Numbers to a File</a> <small> photo credit: Mykl Roventine This programming challenge is from...</small></li>
<li><a href='http://kirkhings.com/code/c/interest-earned/341/' rel='bookmark' title='Permanent Link: Interest Earned'>Interest Earned</a> <small> photo credit: conorwithonen This programming challenge is from an...</small></li>
<li><a href='http://kirkhings.com/code/c/box-office-ticket-sales/159/' rel='bookmark' title='Permanent Link: Box Office Ticket Sales'>Box Office Ticket Sales</a> <small> photo credit: © Natalia Balcerska Photography This programming challenge...</small></li>
</ul>]]></description>
			<content:encoded><![CDATA[<div class="borrowedPic"><a href="http://www.flickr.com/photos/82312837@N00/466713478/" title="Teaching Math or Something" target="_blank"><img src="http://farm1.static.flickr.com/193/466713478_eb670b9ecd.jpg" alt="Teaching Math or Something" border="0" /></a><br /><small><a href="http://creativecommons.org/licenses/by/2.0/" title="Attribution License" target="_blank"><img src="http://kirkhings.com/wp-content/plugins/photo-dropper/images/cc.png" alt="Creative Commons License" border="0" width="16" height="16" align="absmiddle" /></a> <a href="http://www.photodropper.com/photos/" target="_blank">photo</a> credit: <a href="http://www.flickr.com/photos/82312837@N00/466713478/" title="foundphotoslj" target="_blank">foundphotoslj</a></small></div>
<blockquote><p>4.9: This is a modification of Chapter 3&#8217;s Problem 15, which was:</p>
<p>Write a program that can be used as a math tutor for a young student. The program should display two random numbers to be added, such as </p>
<pre>
   247
+ 129
------
</pre>
<p>The program should then pause while the student works on the problem. When the student is ready to check the answer, he or she can press a key and the program will display the correct solution, for example:</p>
<pre>
   247
+ 129
------
   376
</pre>
<p>This time, write a program that can be used as a math tutor for a young student. The program should display two random numbers that are to be added. The program should wait for the student to enter the answer. If the answer is correct, a message of congratulations should be printed. If the answer is incorrect, a message should be printed showing the correct answer.
</p></blockquote>
<p>My solution:</p>
<pre class="brush: cpp;">
/* Chapter 4 Challenge 9
   Written by Kirk Hingsberger
   October 3, 2007
   Math Tutor - Enhanced
*/

#include &lt;iomanip&gt;
#include &lt;cstdlib&gt;
#include &lt;ctime&gt;
#include &lt;iostream&gt;
using namespace std;

int main()
{
  char ch;
  srand(time(0));
  const int SEED = 999;
  int num1, num2, num3, answer;

  num1 = 1 + rand() % SEED;
  num2 = 1 + rand() % SEED;

  cout &lt;&lt; &quot;Enter your answer after the problem appears:&quot; &lt;&lt; endl;
  cout &lt;&lt; setw(5) &lt;&lt; num1 &lt;&lt; endl;
  cout &lt;&lt; &quot;+ &quot; &lt;&lt; setw(3) &lt;&lt; num2 &lt;&lt; endl;
  cout &lt;&lt; &quot;_____&quot; &lt;&lt; endl;
  cin &gt;&gt; answer;
  num3 = num1 + num2;
  cin.get(ch);

  cout &lt;&lt; setw(5) &lt;&lt; num3 &lt;&lt; &quot; is the correct answer, &quot;;

  if (answer == num3)
    {
      cout &lt;&lt; &quot;great job!&quot; &lt;&lt; endl;
    }
  else if (answer &gt; num3)
    {
      cout &lt;&lt; &quot;your answer (&quot; &lt;&lt; answer &lt;&lt; &quot;) was too high.&quot; &lt;&lt; endl;
    }
  else
    {
      cout &lt;&lt; &quot;your answer (&quot; &lt;&lt; answer &lt;&lt; &quot;) was too low.&quot; &lt;&lt; endl;
    }

  return 0;
}
</pre>
<p>Note: This programming challenge is from an initial C++ programming course I took in Fall 2007. The Chapter (4) was titled &#8220;Making Decisions&#8221;.</p>
<p>I post these old academic challenges for a few reasons. One is to demonstrate my programming learning, experience, and progression. Another reason is to make sure my code and solutions are indexed by search engines, so that other beginning programmers may get help if they need it.</p>


<p>Related posts:<ul><li><a href='http://kirkhings.com/code/c/math-tutor/331/' rel='bookmark' title='Permanent Link: Math Tutor'>Math Tutor</a> <small> photo credit: *Zara This programming challenge is from an...</small></li>
<li><a href='http://kirkhings.com/code/c/saving-numbers-to-a-file/348/' rel='bookmark' title='Permanent Link: Saving Numbers to a File'>Saving Numbers to a File</a> <small> photo credit: Mykl Roventine This programming challenge is from...</small></li>
<li><a href='http://kirkhings.com/code/c/interest-earned/341/' rel='bookmark' title='Permanent Link: Interest Earned'>Interest Earned</a> <small> photo credit: conorwithonen This programming challenge is from an...</small></li>
<li><a href='http://kirkhings.com/code/c/box-office-ticket-sales/159/' rel='bookmark' title='Permanent Link: Box Office Ticket Sales'>Box Office Ticket Sales</a> <small> photo credit: © Natalia Balcerska Photography This programming challenge...</small></li>
</ul></p>]]></content:encoded>
			<wfw:commentRss>http://kirkhings.com/code/c/math-tutor-enhanced/417/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Time Calculator</title>
		<link>http://kirkhings.com/code/c/time-calculator/415/</link>
		<comments>http://kirkhings.com/code/c/time-calculator/415/#comments</comments>
		<pubDate>Tue, 09 Jun 2009 03:14:02 +0000</pubDate>
		<dc:creator>Kirk</dc:creator>
				<category><![CDATA[C++]]></category>
		<category><![CDATA[academic challenge]]></category>

		<guid isPermaLink="false">http://kirkhings.com/?p=415</guid>
		<description><![CDATA[ photo credit: FABIOLA MEDEIROS- direção de arte
This programming challenge is from an initial C++ programming course I took in Fall 2007. The Chapter (4) was titled &#8220;Making Decisions&#8221;.
I post these old academic challenges for a few reasons. One is to demonstrate my programming learning, experience, and progression. Another reason is to make sure my [...]


Related posts:<ul><li><a href='http://kirkhings.com/code/c/interest-earned/341/' rel='bookmark' title='Permanent Link: Interest Earned'>Interest Earned</a> <small> photo credit: conorwithonen This programming challenge is from an...</small></li>
<li><a href='http://kirkhings.com/code/c/test-scores-and-letter-grade/413/' rel='bookmark' title='Permanent Link: Test Scores and Letter Grade'>Test Scores and Letter Grade</a> <small> photo credit: quinn.anya This programming challenge is from an...</small></li>
<li><a href='http://kirkhings.com/code/c/math-tutor-enhanced/417/' rel='bookmark' title='Permanent Link: Math Tutor Enhanced'>Math Tutor Enhanced</a> <small> photo credit: foundphotoslj 4.9: This is a modification of...</small></li>
<li><a href='http://kirkhings.com/code/c/box-office-ticket-sales/159/' rel='bookmark' title='Permanent Link: Box Office Ticket Sales'>Box Office Ticket Sales</a> <small> photo credit: © Natalia Balcerska Photography This programming challenge...</small></li>
</ul>]]></description>
			<content:encoded><![CDATA[<div class="borrowedPic"><a href="http://www.flickr.com/photos/66355718@N00/206950948/" title="TIME" target="_blank"><img src="http://farm1.static.flickr.com/79/206950948_6c822f621f.jpg" alt="TIME" border="0" /></a><br /><small><a href="http://creativecommons.org/licenses/by/2.0/" title="Attribution License" target="_blank"><img src="http://kirkhings.com/wp-content/plugins/photo-dropper/images/cc.png" alt="Creative Commons License" border="0" width="16" height="16" align="absmiddle" /></a> <a href="http://www.photodropper.com/photos/" target="_blank">photo</a> credit: <a href="http://www.flickr.com/photos/66355718@N00/206950948/" title="FABIOLA MEDEIROS- direção de arte" target="_blank">FABIOLA MEDEIROS- direção de arte</a></small></div>
<p>This programming challenge is from an initial C++ programming course I took in Fall 2007. The Chapter (4) was titled &#8220;Making Decisions&#8221;.</p>
<p>I post these old academic challenges for a few reasons. One is to demonstrate my programming learning, experience, and progression. Another reason is to make sure my code and solutions are indexed by search engines, so that other beginning programmers may get help if they need it.</p>
<blockquote><p>4.7: Write a program that asks the user to enter a number of seconds. </p>
<p>There are 60 seconds in a minute. If the number of seconds entered by the user is greater than or equal to 60, the program should display the number of minutes in that many seconds.</p>
<p>There are 3,600 seconds in an hour. If the number of seconds entered by the user is greater than or equal to 3,600, the program should display the number of hours in that many seconds.</p>
<p>There are 86,400 seconds in a day. If the number of seconds entered by the user is greater than or equal to 86,400, the program should display the number of days in that many seconds.
</p></blockquote>
<p>My solution:</p>
<pre class="brush: cpp;">
/* Chapter 4 Challenge 7
   Written by Kirk Hingsberger
   October 2, 2007
   Time Calculator
*/

#include &lt;iostream&gt;
using namespace std;

int main()
{
  int seconds;
  float minutes, hours, days;

  cout &lt;&lt; &quot;Please enter a number of seconds.&quot; &lt;&lt; endl;
  cin &gt;&gt; seconds;

  if (seconds &gt;= 86400)
    {
      days = seconds / 86400.0;
      cout &lt;&lt; &quot;You entered &quot; &lt;&lt; seconds &lt;&lt; &quot;, which equals &quot;
	   &lt;&lt; days &lt;&lt; &quot; days.&quot; &lt;&lt; endl;
    }

  else if (seconds &gt;= 3600)
    {
      hours = seconds / 3600.0;
      cout &lt;&lt; &quot;You entered &quot; &lt;&lt; seconds &lt;&lt; &quot;, which equals &quot;
	   &lt;&lt; hours &lt;&lt; &quot; hours.&quot; &lt;&lt; endl;
    }
  else if (seconds &gt;= 60)
    {
      minutes = seconds / 60.0;
      cout &lt;&lt; &quot;You entered &quot; &lt;&lt; seconds &lt;&lt; &quot;, which equals &quot;
	   &lt;&lt; minutes &lt;&lt; &quot; minutes.&quot; &lt;&lt; endl;
    }
  else
    cout &lt;&lt; &quot;You entered &quot; &lt;&lt; seconds &lt;&lt; &quot; seconds.&quot; &lt;&lt; endl;

  return 0;
}
</pre>
<p>Here is the capture script I turned in for grading:</p>
<pre class="brush: cpp;">
Script started on Tue 02 Oct 2007 12:06:37 PM MDT
$ cat chap4chlg7.cc
/* Chapter 4 Challenge 7
   Written by Kirk Hingsberger
   October 2, 2007
   Time Calculator
*/

#include &lt;iostream&gt;
using namespace std;

int main()
{
  int seconds;
  float minutes, hours, days;

  cout &lt;&lt; &quot;Please enter a number of seconds.&quot; &lt;&lt; endl;
  cin &gt;&gt; seconds;

  if (seconds &gt;= 86400)
    {
      days = seconds / 86400.0;
      cout &lt;&lt; &quot;You entered &quot; &lt;&lt; seconds &lt;&lt; &quot;, which equals &quot;
	   &lt;&lt; days &lt;&lt; &quot; days.&quot; &lt;&lt; endl;
    }

  else if (seconds &gt;= 3600)
    {
      hours = seconds / 3600.0;
      cout &lt;&lt; &quot;You entered &quot; &lt;&lt; seconds &lt;&lt; &quot;, which equals &quot;
	   &lt;&lt; hours &lt;&lt; &quot; hours.&quot; &lt;&lt; endl;
    }
  else if (seconds &gt;= 60)
    {
      minutes = seconds / 60.0;
      cout &lt;&lt; &quot;You entered &quot; &lt;&lt; seconds &lt;&lt; &quot;, which equals &quot;
	   &lt;&lt; minutes &lt;&lt; &quot; minutes.&quot; &lt;&lt; endl;
    }
  else
    cout &lt;&lt; &quot;You entered &quot; &lt;&lt; seconds &lt;&lt; &quot; seconds.&quot; &lt;&lt; endl;

  return 0;
}
$ g++ -o chap4chlg7 chap4chlg7.cc -s
$ chap4chlg7
Please enter a number of seconds.
59
You entered 59 seconds.
$ chap4chlg7
Please enter a number of seconds.
62
You entered 62, which equals 1.03333 minutes.
$ chap4chlg7
Please enter a number of seconds.
3599
You entered 3599, which equals 59.9833 minutes.
$ chap4chlg7
Please enter a number of seconds.
3604
You entered 3604, which equals 1.00111 hours.
$ chap4chlg7
Please enter a number of seconds.
86399
You entered 86399, which equals 23.9997 hours.
$ chap4chlg7
Please enter a number of seconds.
86401
You entered 86401, which equals 1.00001 days.
$ chap4chlg7
Please enter a number of seconds.
123456789
You entered 123456789, which equals 1428.9 days.
$ exit
exit

Script done on Tue 02 Oct 2007 12:07:33 PM MDT
</pre>
<p>I later went back and expanded my solution to output in more formats at each level:</p>
<pre class="brush: cpp;">
/* Chapter 4 Challenge 7 (Expanded Solution)
   Written by Kirk Hingsberger
   October 2, 2007
   Time Calculator
*/

#include &lt;iomanip&gt;
#include &lt;iostream&gt;
using namespace std;

int main()
{
  int seconds;
  int minutes, hours, days;

  cout &lt;&lt; &quot;Please enter a number of seconds.&quot; &lt;&lt; endl;
  cin &gt;&gt; seconds;

  if (seconds &gt;= 86400)
    {
      days = seconds / 86400;
      cout &lt;&lt; &quot;Number of days: &quot; &lt;&lt; setw(8) &lt;&lt; days &lt;&lt; endl;
      seconds = seconds % 86400;
      hours = seconds / 3600;
      cout &lt;&lt; &quot;Number of hours: &quot; &lt;&lt; setw(7) &lt;&lt; hours &lt;&lt; endl;
      seconds = seconds % 3600;
      minutes = seconds / 60;
      cout &lt;&lt; &quot;Number of minutes: &quot; &lt;&lt; setw(5) &lt;&lt; minutes &lt;&lt; endl;
      seconds = seconds % 60;
      cout &lt;&lt; &quot;Number of seconds: &quot; &lt;&lt; setw(5) &lt;&lt; seconds &lt;&lt; endl;
    }
  else if (seconds &gt;= 3600)
    {
      hours = seconds / 3600;
      cout &lt;&lt; &quot;Number of hours: &quot; &lt;&lt; setw(7) &lt;&lt; hours &lt;&lt; endl;
      seconds = seconds % 3600;
      minutes = seconds / 60;
      cout &lt;&lt; &quot;Number of minutes: &quot; &lt;&lt; setw(5) &lt;&lt; minutes &lt;&lt; endl;
      seconds = seconds % 60;
      cout &lt;&lt; &quot;Number of seconds: &quot; &lt;&lt; setw(5) &lt;&lt; seconds &lt;&lt; endl;
    }
  else if (seconds &gt;= 60)
    {
      minutes = seconds / 60;
      cout &lt;&lt; &quot;Number of minutes: &quot; &lt;&lt; setw(5) &lt;&lt; minutes &lt;&lt; endl;
      seconds = seconds % 60;
      cout &lt;&lt; &quot;Number of seconds: &quot; &lt;&lt; setw(5) &lt;&lt; seconds &lt;&lt; endl;
    }
  else
    {
      cout &lt;&lt; &quot;Number of seconds: &quot; &lt;&lt; setw(5) &lt;&lt; seconds &lt;&lt; endl;
    }

  return 0;
}
</pre>


<p>Related posts:<ul><li><a href='http://kirkhings.com/code/c/interest-earned/341/' rel='bookmark' title='Permanent Link: Interest Earned'>Interest Earned</a> <small> photo credit: conorwithonen This programming challenge is from an...</small></li>
<li><a href='http://kirkhings.com/code/c/test-scores-and-letter-grade/413/' rel='bookmark' title='Permanent Link: Test Scores and Letter Grade'>Test Scores and Letter Grade</a> <small> photo credit: quinn.anya This programming challenge is from an...</small></li>
<li><a href='http://kirkhings.com/code/c/math-tutor-enhanced/417/' rel='bookmark' title='Permanent Link: Math Tutor Enhanced'>Math Tutor Enhanced</a> <small> photo credit: foundphotoslj 4.9: This is a modification of...</small></li>
<li><a href='http://kirkhings.com/code/c/box-office-ticket-sales/159/' rel='bookmark' title='Permanent Link: Box Office Ticket Sales'>Box Office Ticket Sales</a> <small> photo credit: © Natalia Balcerska Photography This programming challenge...</small></li>
</ul></p>]]></content:encoded>
			<wfw:commentRss>http://kirkhings.com/code/c/time-calculator/415/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Test Scores and Letter Grade</title>
		<link>http://kirkhings.com/code/c/test-scores-and-letter-grade/413/</link>
		<comments>http://kirkhings.com/code/c/test-scores-and-letter-grade/413/#comments</comments>
		<pubDate>Mon, 08 Jun 2009 04:20:49 +0000</pubDate>
		<dc:creator>Kirk</dc:creator>
				<category><![CDATA[C++]]></category>
		<category><![CDATA[academic challenge]]></category>

		<guid isPermaLink="false">http://kirkhings.com/?p=413</guid>
		<description><![CDATA[ photo credit: quinn.anya
This programming challenge is from an initial C++ programming course I took in Fall 2007. The Chapter (4) was titled &#8220;Making Decisions&#8221;.
I post these old academic challenges for a few reasons. One is to demonstrate my programming learning, experience, and progression. Another reason is to make sure my code and solutions are [...]


Related posts:<ul><li><a href='http://kirkhings.com/code/c/test-average/156/' rel='bookmark' title='Permanent Link: Test Average'>Test Average</a> <small> photo credit: ccarlstead This programming challenge is from an...</small></li>
<li><a href='http://kirkhings.com/code/c/average-rainfall/139/' rel='bookmark' title='Permanent Link: Average Rainfall'>Average Rainfall</a> <small> photo credit: quapan This programming challenge is from an...</small></li>
<li><a href='http://kirkhings.com/code/c/average-of-values/90/' rel='bookmark' title='Permanent Link: Average of Values'>Average of Values</a> <small> photo credit: psd This programming challenge is from an...</small></li>
<li><a href='http://kirkhings.com/code/c/interest-earned/341/' rel='bookmark' title='Permanent Link: Interest Earned'>Interest Earned</a> <small> photo credit: conorwithonen This programming challenge is from an...</small></li>
</ul>]]></description>
			<content:encoded><![CDATA[<div class="borrowedPic"><a href="http://www.flickr.com/photos/53326337@N00/3592746676/" title="Discussion of grades" target="_blank"><img src="http://farm4.static.flickr.com/3652/3592746676_fa5ac8852d.jpg" alt="Discussion of grades" border="0" /></a><br /><small><a href="http://creativecommons.org/licenses/by-sa/2.0/" title="Attribution-ShareAlike License" target="_blank"><img src="http://kirkhings.com/wp-content/plugins/photo-dropper/images/cc.png" alt="Creative Commons License" border="0" width="16" height="16" align="absmiddle" /></a> <a href="http://www.photodropper.com/photos/" target="_blank">photo</a> credit: <a href="http://www.flickr.com/photos/53326337@N00/3592746676/" title="quinn.anya" target="_blank">quinn.anya</a></small></div>
<p>This programming challenge is from an initial C++ programming course I took in Fall 2007. The Chapter (4) was titled &#8220;Making Decisions&#8221;.</p>
<p>I post these old academic challenges for a few reasons. One is to demonstrate my programming learning, experience, and progression. Another reason is to make sure my code and solutions are indexed by search engines, so that other beginning programmers may get help if they need it.</p>
<blockquote><p>4.5: Test Scores and Letter Grade:<br />
Write a program that has variables to hold three test scores. The program should ask the user to enter three test scores and then assign the values entered to the variables. The program should display the average of the test scores and the letter grade that is assigned for the test score average. Use the following grade scheme: 90 or greater = A, 80-89 = B, 70-79 = C, 60-69 = D, Below 60 = F. Assume valid user inputs.
</p></blockquote>
<p>My solution:</p>
<pre class="brush: cpp;">
/* Chapter 4 Challenge 5
   Written by Kirk Hingsberger
   October 2, 2007
   Test scroes and grade
*/

#include &lt;iostream&gt;
using namespace std;

int main()
{
  float test1, test2, test3, avg;

  cout &lt;&lt; &quot;Please enter your three test scores each separated by a space.\n&quot;;
  cin &gt;&gt; test1 &gt;&gt; test2 &gt;&gt; test3;

  avg = (test1 + test2 + test3) / 3;

  cout &lt;&lt; &quot;Your test average &quot; &lt;&lt; avg &lt;&lt; &quot; earned you an &quot;;

  if (avg &gt; 90)
    {
      cout &lt;&lt; &quot;A.&quot; &lt;&lt; endl;
    }
  else if (avg &gt; 80)
    {
      cout &lt;&lt; &quot;B.&quot; &lt;&lt; endl;
    }
  else if (avg &gt; 70)
    {
      cout &lt;&lt; &quot;C.&quot; &lt;&lt; endl;
    }
  else if (avg &gt; 60)
    {
      cout &lt;&lt; &quot;D.&quot; &lt;&lt; endl;
    }
  else
    {
      cout &lt;&lt; &quot;F.&quot; &lt;&lt; endl;
    }

  return 0;
}
</pre>
<p>Here is the capture script I turned in for grading:</p>
<pre class="brush: cpp;">
Script started on Tue 02 Oct 2007 11:21:02 AM MDT
$ cat chap4chlg5.cc
/* Chapter 4 Challenge 5
   Written by Kirk Hingsberger
   October 2, 2007
   Test scroes and grade
*/

#include &lt;iostream&gt;
using namespace std;

int main()
{
  float test1, test2, test3, avg;

  cout &lt;&lt; &quot;Please enter your three test scores each separated by a space.\n&quot;;
  cin &gt;&gt; test1 &gt;&gt; test2 &gt;&gt; test3;

  avg = (test1 + test2 + test3) / 3;

  cout &lt;&lt; &quot;Your test average &quot; &lt;&lt; avg &lt;&lt; &quot; earned you &quot;;

  if (avg &gt; 90)
    {
      cout &lt;&lt; &quot;an A.&quot; &lt;&lt; endl;
    }
  else if (avg &gt; 80)
    {
      cout &lt;&lt; &quot;a B.&quot; &lt;&lt; endl;
    }
  else if (avg &gt; 70)
    {
      cout &lt;&lt; &quot;a C.&quot; &lt;&lt; endl;
    }
  else if (avg &gt; 60)
    {
      cout &lt;&lt; &quot;a D.&quot; &lt;&lt; endl;
    }
  else
    {
      cout &lt;&lt; &quot;an F.&quot; &lt;&lt; endl;
    }

  return 0;
}
$ g++ -o chap4chlg5 chap4chlg5.cc -s
$ chap4chlg5
Please enter your three test scores each separated by a space.
44.5 84.5 99.9
Your test average 76.3 earned you a C.
$ exit
exit

Script done on Tue 02 Oct 2007 11:21:41 AM MDT
</pre>


<p>Related posts:<ul><li><a href='http://kirkhings.com/code/c/test-average/156/' rel='bookmark' title='Permanent Link: Test Average'>Test Average</a> <small> photo credit: ccarlstead This programming challenge is from an...</small></li>
<li><a href='http://kirkhings.com/code/c/average-rainfall/139/' rel='bookmark' title='Permanent Link: Average Rainfall'>Average Rainfall</a> <small> photo credit: quapan This programming challenge is from an...</small></li>
<li><a href='http://kirkhings.com/code/c/average-of-values/90/' rel='bookmark' title='Permanent Link: Average of Values'>Average of Values</a> <small> photo credit: psd This programming challenge is from an...</small></li>
<li><a href='http://kirkhings.com/code/c/interest-earned/341/' rel='bookmark' title='Permanent Link: Interest Earned'>Interest Earned</a> <small> photo credit: conorwithonen This programming challenge is from an...</small></li>
</ul></p>]]></content:encoded>
			<wfw:commentRss>http://kirkhings.com/code/c/test-scores-and-letter-grade/413/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Area of Rectangles</title>
		<link>http://kirkhings.com/code/c/area-of-rectangles/411/</link>
		<comments>http://kirkhings.com/code/c/area-of-rectangles/411/#comments</comments>
		<pubDate>Mon, 08 Jun 2009 02:32:57 +0000</pubDate>
		<dc:creator>Kirk</dc:creator>
				<category><![CDATA[C++]]></category>
		<category><![CDATA[academic challenge]]></category>

		<guid isPermaLink="false">http://kirkhings.com/?p=411</guid>
		<description><![CDATA[ photo credit: shaire productions
This programming challenge is from an initial C++ programming course I took in Fall 2007. The Chapter (4) was titled &#8220;Making Decisions&#8221;.
I post these old academic challenges for a few reasons. One is to demonstrate my programming learning, experience, and progression. Another reason is to make sure my code and solutions [...]


Related posts:<ul><li><a href='http://kirkhings.com/code/c/average-rainfall/139/' rel='bookmark' title='Permanent Link: Average Rainfall'>Average Rainfall</a> <small> photo credit: quapan This programming challenge is from an...</small></li>
<li><a href='http://kirkhings.com/code/c/pizza-pi/153/' rel='bookmark' title='Permanent Link: Pizza Pi'>Pizza Pi</a> <small> photo credit: callme_crochet This programming challenge is from an...</small></li>
<li><a href='http://kirkhings.com/code/c/time-calculator/415/' rel='bookmark' title='Permanent Link: Time Calculator'>Time Calculator</a> <small> photo credit: FABIOLA MEDEIROS- direção de arte This programming...</small></li>
<li><a href='http://kirkhings.com/code/c/interest-earned/341/' rel='bookmark' title='Permanent Link: Interest Earned'>Interest Earned</a> <small> photo credit: conorwithonen This programming challenge is from an...</small></li>
</ul>]]></description>
			<content:encoded><![CDATA[<div class="borrowedPic"><a href="http://www.flickr.com/photos/9822107@N08/2590014845/" title="Swirly Tiles 02" target="_blank"><img src="http://farm4.static.flickr.com/3289/2590014845_1a8a3a93eb.jpg" alt="Swirly Tiles 02" border="0" /></a><br /><small><a href="http://creativecommons.org/licenses/by/2.0/" title="Attribution License" target="_blank"><img src="http://kirkhings.com/wp-content/plugins/photo-dropper/images/cc.png" alt="Creative Commons License" border="0" width="16" height="16" align="absmiddle" /></a> <a href="http://www.photodropper.com/photos/" target="_blank">photo</a> credit: <a href="http://www.flickr.com/photos/9822107@N08/2590014845/" title="shaire productions" target="_blank">shaire productions</a></small></div>
<p>This programming challenge is from an initial C++ programming course I took in Fall 2007. The Chapter (4) was titled &#8220;Making Decisions&#8221;.</p>
<p>I post these old academic challenges for a few reasons. One is to demonstrate my programming learning, experience, and progression. Another reason is to make sure my code and solutions are indexed by search engines, so that other beginning programmers may get help if they need it.</p>
<blockquote><p>4.4: Area of Rectangles: The area of a rectangle is the rectangle&#8217;s length times its width. Write a program that asks for the length and width of two rectangles. The program should tell the user which rectangle has the greater area, or if the areas are the same.
</p></blockquote>
<p>My solution:</p>
<pre class="brush: cpp;">
/* Chapter 4 Challenge 4
   Written by Kirk Hingsberger
   October 2, 2007
   Comparing rectangle areas
*/

#include &lt;iostream&gt;
using namespace std;

int main()
{
  float width1, width2, length1, length2, rect1, rect2;

  cout &lt;&lt; &quot;Enter inches width of first rectangle: &quot;;
  cin &gt;&gt; width1;
  cout &lt;&lt; &quot;Enter inches length of first rectangle: &quot;;
  cin &gt;&gt; length1;
  cout &lt;&lt; &quot;Enter inches width of second rectangle: &quot;;
  cin &gt;&gt; width2;
  cout &lt;&lt; &quot;Enter inches length of second rectangle: &quot;;
  cin &gt;&gt; length2;

  rect1 = width1 * length1;
  rect2 = width2 * length2;

  if (rect1 &gt; rect2)
    {
      cout &lt;&lt; &quot;Rectangle 1 (&quot; &lt;&lt; rect1 &lt;&lt; &quot;) is &quot; &lt;&lt; rect1 - rect2
	   &lt;&lt; &quot; area inches larger than rectangle 2 (&quot;
	   &lt;&lt; rect2 &lt;&lt; &quot;).&quot; &lt;&lt; endl;
    }
  else if (rect1 &lt; rect2)
    {
      cout &lt;&lt; &quot;Rectangle 2 (&quot; &lt;&lt; rect2 &lt;&lt; &quot;) is &quot; &lt;&lt; rect2 - rect1
	   &lt;&lt; &quot; area inches larger than rectangle 1 (&quot;
	   &lt;&lt; rect1 &lt;&lt; &quot;).&quot; &lt;&lt; endl;
    }
  else if (rect1 == rect2)
    {
      cout &lt;&lt; &quot;Rectangles 1 and 2 are equal at &quot;
	   &lt;&lt; rect1 &lt;&lt; &quot; area inches.&quot; &lt;&lt; endl;
    }

  return 0;
}
</pre>
<p>Here is the capture script I turned in for grading:</p>
<pre class="brush: cpp;">
Script started on Tue 02 Oct 2007 10:49:54 AM MDT
$ cat chap4chlg4.cc
/* Chapter 4 Challenge 4
   Written by Kirk Hingsberger
   October 2, 2007
   Comparing rectangle areas
*/

#include &lt;iostream&gt;
using namespace std;

int main()
{
  float width1, width2, length1, length2, rect1, rect2;

  cout &lt;&lt; &quot;Enter inches width of first rectangle: &quot;;
  cin &gt;&gt; width1;
  cout &lt;&lt; &quot;Enter inches length of first rectangle: &quot;;
  cin &gt;&gt; length1;
  cout &lt;&lt; &quot;Enter inches width of second rectangle: &quot;;
  cin &gt;&gt; width2;
  cout &lt;&lt; &quot;Enter inches length of second rectangle: &quot;;
  cin &gt;&gt; length2;

  rect1 = width1 * length1;
  rect2 = width2 * length2;

  if (rect1 &gt; rect2)
    {
      cout &lt;&lt; &quot;Rectangle 1 (&quot; &lt;&lt; rect1 &lt;&lt; &quot;) is &quot; &lt;&lt; rect1 - rect2
	   &lt;&lt; &quot; area inches larger than rectangle 2 (&quot;
	   &lt;&lt; rect2 &lt;&lt; &quot;).&quot; &lt;&lt; endl;
    }
  else if (rect1 &lt; rect2)
    {
      cout &lt;&lt; &quot;Rectangle 2 (&quot; &lt;&lt; rect2 &lt;&lt; &quot;) is &quot; &lt;&lt; rect2 - rect1
	   &lt;&lt; &quot; area inches larger than rectangle 1 (&quot;
	   &lt;&lt; rect1 &lt;&lt; &quot;).&quot; &lt;&lt; endl;
    }
  else if (rect1 == rect2)
    {
      cout &lt;&lt; &quot;Rectangles 1 and 2 are equal at &quot;
	   &lt;&lt; rect1 &lt;&lt; &quot; area inches.&quot; &lt;&lt; endl;
    }

  return 0;
}
$ g++ -o chap4chlg4 chapr4chlg4.cc -s
$ chap4chlg4
Enter inches width of first rectangle: 2
Enter inches length of first rectangle: 3
Enter inches width of second rectangle: 3
Enter inches length of second rectangle: 4
Rectangle 2 (12) is 6 area inches larger than rectangle 1 (6).
$ chap4chlg4
Enter inches width of first rectangle: 4
Enter inches length of first rectangle: 3
Enter inches width of second rectangle: 3
Enter inches length of second rectangle: 2
Rectangle 1 (12) is 6 area inches larger than rectangle 2 (6).
$ chap4chlg4
Enter inches width of first rectangle: 2
Enter inches length of first rectangle: 3
Enter inches width of second rectangle: 2
Enter inches length of second rectangle: 3
Rectangles 1 and 2 are equal at 6 area inches.
$ exit
exit

Script done on Tue 02 Oct 2007 10:50:40 AM MDT
</pre>


<p>Related posts:<ul><li><a href='http://kirkhings.com/code/c/average-rainfall/139/' rel='bookmark' title='Permanent Link: Average Rainfall'>Average Rainfall</a> <small> photo credit: quapan This programming challenge is from an...</small></li>
<li><a href='http://kirkhings.com/code/c/pizza-pi/153/' rel='bookmark' title='Permanent Link: Pizza Pi'>Pizza Pi</a> <small> photo credit: callme_crochet This programming challenge is from an...</small></li>
<li><a href='http://kirkhings.com/code/c/time-calculator/415/' rel='bookmark' title='Permanent Link: Time Calculator'>Time Calculator</a> <small> photo credit: FABIOLA MEDEIROS- direção de arte This programming...</small></li>
<li><a href='http://kirkhings.com/code/c/interest-earned/341/' rel='bookmark' title='Permanent Link: Interest Earned'>Interest Earned</a> <small> photo credit: conorwithonen This programming challenge is from an...</small></li>
</ul></p>]]></content:encoded>
			<wfw:commentRss>http://kirkhings.com/code/c/area-of-rectangles/411/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Diner Specials Display</title>
		<link>http://kirkhings.com/code/visual-basic-code/diner-specials-display/375/</link>
		<comments>http://kirkhings.com/code/visual-basic-code/diner-specials-display/375/#comments</comments>
		<pubDate>Fri, 15 May 2009 04:57:44 +0000</pubDate>
		<dc:creator>Kirk</dc:creator>
				<category><![CDATA[Visual Basic]]></category>
		<category><![CDATA[academic challenge]]></category>
		<category><![CDATA[visual basic]]></category>

		<guid isPermaLink="false">http://kirkhings.com/?p=375</guid>
		<description><![CDATA[ photo credit: wEnDaLicious
This programming challenge is from a Visual Basic.Net programming course I took in Spring 2008. The Chapter (1) was titled &#8220;Introduction to Visual Basic .Net 2005&#8243;.
I post these old academic challenges for a few reasons. One is to demonstrate my programming learning, experience, and progression. Another reason is to make sure my [...]


Related posts:<ul><li><a href='http://kirkhings.com/code/visual-basic-code/button-driven-quotes/352/' rel='bookmark' title='Permanent Link: Button-Driven Quotes'>Button-Driven Quotes</a> <small> photo credit: bogenfreund This programming challenge is from a...</small></li>
</ul>]]></description>
			<content:encoded><![CDATA[<div class="borrowedPic"><a href="http://www.flickr.com/photos/25597828@N00/1066580415/" title="Sandwich @ Tick Tock Diner - 481 8th Ave" target="_blank"><img src="http://farm2.static.flickr.com/1277/1066580415_552e34b1ff.jpg" alt="Sandwich @ Tick Tock Diner - 481 8th Ave" border="0" /></a><br /><small><a href="http://creativecommons.org/licenses/by-nd/2.0/" title="Attribution-NoDerivs License" target="_blank"><img src="http://kirkhings.com/wp-content/plugins/photo-dropper/images/cc.png" alt="Creative Commons License" border="0" width="16" height="16" align="absmiddle" /></a> <a href="http://www.photodropper.com/photos/" target="_blank">photo</a> credit: <a href="http://www.flickr.com/photos/25597828@N00/1066580415/" title="wEnDaLicious" target="_blank">wEnDaLicious</a></small></div>
<p>This programming challenge is from a Visual Basic.Net programming course I took in Spring 2008. The Chapter (1) was titled &#8220;Introduction to Visual Basic .Net 2005&#8243;.</p>
<p>I post these old academic challenges for a few reasons. One is to demonstrate my programming learning, experience, and progression. Another reason is to make sure my code and solutions are indexed by search engines, so that other beginning programmers may get help if they need it.</p>
<blockquote><p>1.5: Create a project to display the daily specials for &#8220;your&#8221; diner. Make up a name for your diner and display it in a label at the top of the form. Add a label to display the appropriate special depending on the button that is pressed. the buttons should be:</p>
<ul>
<li>Soup of the Day</li>
<li>Chef&#8217;s Special</li>
<li>Daily Fish</li>
</ul>
<p>Also include an Exit button.
</p></blockquote>
<p>My solution code:</p>
<pre class="brush: vb;">
' Assignment 1
' Problem 1.5
' Kirk Hingsberger
' Display Menu Specials

Public Class specialsForm
    Private Sub exitButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles exitButton.Click
        ' Exits program
        Me.Close()
    End Sub

    Private Sub soupButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles soupButton.Click
        ' Display Soup of Day
        Me.specialsTextLabel.Text = &quot;Kirk's Diner is offering hot hot water as our soup of the day.&quot;
    End Sub

    Private Sub chefsButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chefsButton.Click
        ' Display Chef's Special
        Me.specialsTextLabel.Text = &quot;Kirk's Diner is offering yesterday's leftovers as our premium chef's special today.&quot;
    End Sub

    Private Sub fishButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles fishButton.Click
        ' Display Daily Fish
        Me.specialsTextLabel.Text = &quot;Kirk's Diner is offering fillet of oscar as today's daily fish special.&quot;
    End Sub
End Class
</pre>
<p>My solution&#8217;s build screenshot:</p>
<div id="attachment_376" class="wp-caption alignleft" style="width: 410px"><img src="http://kirkhings.com/wp-content/uploads/vb1-5.png" alt="Press a button to get a diner special" title="vb1-5" width="400" height="301" class="size-full wp-image-376" /><p class="wp-caption-text">Press a button to get a diner special</p></div>


<p>Related posts:<ul><li><a href='http://kirkhings.com/code/visual-basic-code/button-driven-quotes/352/' rel='bookmark' title='Permanent Link: Button-Driven Quotes'>Button-Driven Quotes</a> <small> photo credit: bogenfreund This programming challenge is from a...</small></li>
</ul></p>]]></content:encoded>
			<wfw:commentRss>http://kirkhings.com/code/visual-basic-code/diner-specials-display/375/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Saving Numbers to a File</title>
		<link>http://kirkhings.com/code/c/saving-numbers-to-a-file/348/</link>
		<comments>http://kirkhings.com/code/c/saving-numbers-to-a-file/348/#comments</comments>
		<pubDate>Thu, 14 May 2009 10:14:18 +0000</pubDate>
		<dc:creator>Kirk</dc:creator>
				<category><![CDATA[C++]]></category>
		<category><![CDATA[academic challenge]]></category>

		<guid isPermaLink="false">http://kirkhings.com/?p=348</guid>
		<description><![CDATA[ photo credit: Mykl Roventine
This programming challenge is from an initial C++ programming course I took in Fall 2007. The Chapter (3) was titled &#8220;Expressions and Interactivity&#8221;.
I post these old academic challenges for a few reasons. One is to demonstrate my programming learning, experience, and progression. Another reason is to make sure my code and [...]


Related posts:<ul><li><a href='http://kirkhings.com/code/c/math-tutor/331/' rel='bookmark' title='Permanent Link: Math Tutor'>Math Tutor</a> <small> photo credit: *Zara This programming challenge is from an...</small></li>
<li><a href='http://kirkhings.com/code/c/math-tutor-enhanced/417/' rel='bookmark' title='Permanent Link: Math Tutor Enhanced'>Math Tutor Enhanced</a> <small> photo credit: foundphotoslj 4.9: This is a modification of...</small></li>
<li><a href='http://kirkhings.com/code/c/average-of-values/90/' rel='bookmark' title='Permanent Link: Average of Values'>Average of Values</a> <small> photo credit: psd This programming challenge is from an...</small></li>
<li><a href='http://kirkhings.com/code/c/monthly-sales-tax/162/' rel='bookmark' title='Permanent Link: Monthly Sales Tax'>Monthly Sales Tax</a> <small> photo credit: mindluge This programming challenge is from an...</small></li>
</ul>]]></description>
			<content:encoded><![CDATA[<div class="borrowedPic"><a href="http://www.flickr.com/photos/64419960@N00/2332789392/" title="Happy Pi Day (to the 36th digit)!" target="_blank"><img src="http://farm3.static.flickr.com/2368/2332789392_6376129e6c.jpg" alt="Happy Pi Day (to the 36th digit)!" border="0" /></a><br /><small><a href="http://creativecommons.org/licenses/by/2.0/" title="Attribution License" target="_blank"><img src="http://kirkhings.com/wp-content/plugins/photo-dropper/images/cc.png" alt="Creative Commons License" border="0" width="16" height="16" align="absmiddle" /></a> <a href="http://www.photodropper.com/photos/" target="_blank">photo</a> credit: <a href="http://www.flickr.com/photos/64419960@N00/2332789392/" title="Mykl Roventine" target="_blank">Mykl Roventine</a></small></div>
<p>This programming challenge is from an initial C++ programming course I took in Fall 2007. The Chapter (3) was titled &#8220;Expressions and Interactivity&#8221;.</p>
<p>I post these old academic challenges for a few reasons. One is to demonstrate my programming learning, experience, and progression. Another reason is to make sure my code and solutions are indexed by search engines, so that other beginning programmers may get help if they need it.</p>
<blockquote><p>3.21: Write two programs:<br />
Program 1: Write a program that asks user to enter five numbers. Use a floating-point data type to hold those numbers. The program should create a file and save all five numbers to the file.<br />
Program 2: Write a program that opens the file created by Program 1, reads the five numbers, and displays them. The program should also calculate and display the sum of the five numbers.
</p></blockquote>
<p>My solution for Program 1:</p>
<pre class="brush: cpp;">
/* Chapter 3 Extra Credit 1
   Written by Kirk Hingsberger
   September 26, 2007
   Saving Numbers to a File, Program 1
*/

#include &lt;fstream&gt;
#include &lt;iostream&gt;
using namespace std;

int main()
{
  float num1, num2, num3, num4, num5;

  cout &lt;&lt; &quot;Enter five numbers, each separated by a space (decimals allowed)&quot; &lt;&lt; endl;
  cin &gt;&gt; num1 &gt;&gt; num2 &gt;&gt; num3 &gt;&gt; num4 &gt;&gt; num5;

  ofstream outputFile;
  outputFile.open(&quot;demofile.txt&quot;);

  cout &lt;&lt; &quot;Now writing those five numbers to demofile.txt file.&quot; &lt;&lt; endl;

  outputFile &lt;&lt; num1 &lt;&lt; endl;
  outputFile &lt;&lt; num2 &lt;&lt; endl;
  outputFile &lt;&lt; num3 &lt;&lt; endl;
  outputFile &lt;&lt; num4 &lt;&lt; endl;
  outputFile &lt;&lt; num5 &lt;&lt; endl;

  outputFile.close();
  cout &lt;&lt; &quot;Finished writing those five numbers to demofile.txt file.&quot; &lt;&lt; endl;

  return 0;
}
</pre>
<p>My solution for Program 2:</p>
<pre class="brush: cpp;">
/* Chapter 3 Extra Credit 2
   Written by Kirk Hingsberger
   September 26, 2007
   Saving Numbers to a File, Program 2
*/

#include &lt;fstream&gt;
#include &lt;iostream&gt;
using namespace std;

int main()
{
  float num1, num2, num3, num4, num5, sum;

  ifstream inFile;

  inFile.open(&quot;demofile.txt&quot;);
  cout &lt;&lt; &quot;Now reading information from demofile.txt...&quot; &lt;&lt; endl;

  inFile &gt;&gt; num1;
  cout &lt;&lt; &quot;num1 is &quot; &lt;&lt; num1 &lt;&lt; endl;

  inFile &gt;&gt; num2;
  cout &lt;&lt; &quot;num2 is &quot; &lt;&lt; num2 &lt;&lt; endl;

  inFile &gt;&gt; num3;
  cout &lt;&lt; &quot;num3 is &quot; &lt;&lt; num3 &lt;&lt; endl;

  inFile &gt;&gt; num4;
  cout &lt;&lt; &quot;num4 is &quot; &lt;&lt; num4 &lt;&lt; endl;

  inFile &gt;&gt; num5;
  cout &lt;&lt; &quot;num5 is &quot; &lt;&lt; num5 &lt;&lt; endl;

  inFile.close();
  cout &lt;&lt; &quot;Closed demofile.txt file.&quot; &lt;&lt; endl;

  sum = num1 + num2 + num3 + num4 + num5;

  cout &lt;&lt; &quot;The sum of these five numbers are &quot; &lt;&lt; sum &lt;&lt; endl;

  return 0;
}
</pre>
<p>Here is the capture script I turned in for grading (Program 1):</p>
<pre class="brush: cpp;">
Script started on Thu 27 Sep 2007 01:32:24 PM MDT
$ cat chap3Extra1.cc
/* Chapter 3 Extra Credit 1
   Written by Kirk Hingsberger
   September 26, 2007
   Saving Numbers to a File, Program 1
*/

#include &lt;fstream&gt;
#include &lt;iostream&gt;
using namespace std;

int main()
{
  float num1, num2, num3, num4, num5;

  cout &lt;&lt; &quot;Enter five numbers, each separated by a space (decimals allowed)&quot; &lt;&lt; endl;
  cin &gt;&gt; num1 &gt;&gt; num2 &gt;&gt; num3 &gt;&gt; num4 &gt;&gt; num5;

  ofstream outputFile;
  outputFile.open(&quot;demofile.txt&quot;);

  cout &lt;&lt; &quot;Now writing those five numbers to demofile.txt file.&quot; &lt;&lt; endl;

  outputFile &lt;&lt; num1 &lt;&lt; endl;
  outputFile &lt;&lt; num2 &lt;&lt; endl;
  outputFile &lt;&lt; num3 &lt;&lt; endl;
  outputFile &lt;&lt; num4 &lt;&lt; endl;
  outputFile &lt;&lt; num5 &lt;&lt; endl;

  outputFile.close();
  cout &lt;&lt; &quot;Finished writing those five numbers to demofile.txt file.&quot; &lt;&lt; endl;

  return 0;
}
$ g++ -o chap3Extra1 chap3Extra1.cc -s
$ chap3Extra1
Enter five numbers, each separated by a space (decimals allowed)
5 55 555 55.55 5.5555
Now writing those five numbers to demofile.txt file.
Finished writing those five numbers to demofile.txt file.
$ exit
exit

Script done on Thu 27 Sep 2007 01:33:09 PM MDT
</pre>
<p>Here is the capture script I turned in for grading (Program 2):</p>
<pre class="brush: cpp;">
Script started on Thu 27 Sep 2007 01:33:18 PM MDT
$ cat chap3Extra2.cc
/* Chapter 3 Extra Credit 2
   Written by Kirk Hingsberger
   September 26, 2007
   Saving Numbers to a File, Program 2
*/

#include &lt;fstream&gt;
#include &lt;iostream&gt;
using namespace std;

int main()
{
  float num1, num2, num3, num4, num5, sum;

  ifstream inFile;

  inFile.open(&quot;demofile.txt&quot;);
  cout &lt;&lt; &quot;Now reading information from demofile.txt...&quot; &lt;&lt; endl;

  inFile &gt;&gt; num1;
  cout &lt;&lt; &quot;num1 is &quot; &lt;&lt; num1 &lt;&lt; endl;

  inFile &gt;&gt; num2;
  cout &lt;&lt; &quot;num2 is &quot; &lt;&lt; num2 &lt;&lt; endl;

  inFile &gt;&gt; num3;
  cout &lt;&lt; &quot;num3 is &quot; &lt;&lt; num3 &lt;&lt; endl;

  inFile &gt;&gt; num4;
  cout &lt;&lt; &quot;num4 is &quot; &lt;&lt; num4 &lt;&lt; endl;

  inFile &gt;&gt; num5;
  cout &lt;&lt; &quot;num5 is &quot; &lt;&lt; num5 &lt;&lt; endl;

  inFile.close();
  cout &lt;&lt; &quot;Closed demofile.txt file.&quot; &lt;&lt; endl;

  sum = num1 + num2 + num3 + num4 + num5;

  cout &lt;&lt; &quot;The sum of these five numbers are &quot; &lt;&lt; sum &lt;&lt; endl;

  return 0;
}
$ g++ -o chap3Extra2 chap3Extra2.cc -s
$ chap3Extra2
Now reading information from demofile.txt...
num1 is 5
num2 is 55
num3 is 555
num4 is 55.55
num5 is 5.5555
Closed demofile.txt file.
The sum of these five numbers are 676.105
$ exit
exit

Script done on Thu 27 Sep 2007 01:33:46 PM MDT
</pre>


<p>Related posts:<ul><li><a href='http://kirkhings.com/code/c/math-tutor/331/' rel='bookmark' title='Permanent Link: Math Tutor'>Math Tutor</a> <small> photo credit: *Zara This programming challenge is from an...</small></li>
<li><a href='http://kirkhings.com/code/c/math-tutor-enhanced/417/' rel='bookmark' title='Permanent Link: Math Tutor Enhanced'>Math Tutor Enhanced</a> <small> photo credit: foundphotoslj 4.9: This is a modification of...</small></li>
<li><a href='http://kirkhings.com/code/c/average-of-values/90/' rel='bookmark' title='Permanent Link: Average of Values'>Average of Values</a> <small> photo credit: psd This programming challenge is from an...</small></li>
<li><a href='http://kirkhings.com/code/c/monthly-sales-tax/162/' rel='bookmark' title='Permanent Link: Monthly Sales Tax'>Monthly Sales Tax</a> <small> photo credit: mindluge This programming challenge is from an...</small></li>
</ul></p>]]></content:encoded>
			<wfw:commentRss>http://kirkhings.com/code/c/saving-numbers-to-a-file/348/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Interest Earned</title>
		<link>http://kirkhings.com/code/c/interest-earned/341/</link>
		<comments>http://kirkhings.com/code/c/interest-earned/341/#comments</comments>
		<pubDate>Wed, 13 May 2009 11:05:40 +0000</pubDate>
		<dc:creator>Kirk</dc:creator>
				<category><![CDATA[C++]]></category>
		<category><![CDATA[academic challenge]]></category>

		<guid isPermaLink="false">http://kirkhings.com/?p=341</guid>
		<description><![CDATA[ photo credit: conorwithonen
This programming challenge is from an initial C++ programming course I took in Fall 2007. The Chapter (3) was titled &#8220;Expressions and Interactivity&#8221;.
I post these old academic challenges for a few reasons. One is to demonstrate my programming learning, experience, and progression. Another reason is to make sure my code and solutions [...]


Related posts:<ul><li><a href='http://kirkhings.com/code/c/time-calculator/415/' rel='bookmark' title='Permanent Link: Time Calculator'>Time Calculator</a> <small> photo credit: FABIOLA MEDEIROS- direção de arte This programming...</small></li>
<li><a href='http://kirkhings.com/code/c/monthly-sales-tax/162/' rel='bookmark' title='Permanent Link: Monthly Sales Tax'>Monthly Sales Tax</a> <small> photo credit: mindluge This programming challenge is from an...</small></li>
<li><a href='http://kirkhings.com/code/c/box-office-ticket-sales/159/' rel='bookmark' title='Permanent Link: Box Office Ticket Sales'>Box Office Ticket Sales</a> <small> photo credit: © Natalia Balcerska Photography This programming challenge...</small></li>
<li><a href='http://kirkhings.com/code/c/total-purchase/95/' rel='bookmark' title='Permanent Link: Total Purchase'>Total Purchase</a> <small> photo credit: Phillie Casablanca This programming challenge is from...</small></li>
</ul>]]></description>
			<content:encoded><![CDATA[<div class="borrowedPic"><a href="http://www.flickr.com/photos/37855887@N00/3095509975/" title="Wow" target="_blank"><img src="http://farm4.static.flickr.com/3105/3095509975_e14ecdc457.jpg" alt="Wow" border="0" /></a><br /><small><a href="http://creativecommons.org/licenses/by-nd/2.0/" title="Attribution-NoDerivs License" target="_blank"><img src="http://kirkhings.com/wp-content/plugins/photo-dropper/images/cc.png" alt="Creative Commons License" border="0" width="16" height="16" align="absmiddle" /></a> <a href="http://www.photodropper.com/photos/" target="_blank">photo</a> credit: <a href="http://www.flickr.com/photos/37855887@N00/3095509975/" title="conorwithonen" target="_blank">conorwithonen</a></small></div>
<p>This programming challenge is from an initial C++ programming course I took in Fall 2007. The Chapter (3) was titled &#8220;Expressions and Interactivity&#8221;.</p>
<p>I post these old academic challenges for a few reasons. One is to demonstrate my programming learning, experience, and progression. Another reason is to make sure my code and solutions are indexed by search engines, so that other beginning programmers may get help if they need it.</p>
<blockquote><p>3.16: Assuming there are no deposits other than the original investment, the balance in a savings account after one year may be calculated as:<br />
Amount = Principal * (1 + (Rate/T))^T<br />
Principal is the balance in the savings account, Rate is the interest rate, and T is the number of times the interest is compounded during a year (T is 4 if the interest is compounded quarterly).</p>
<p>Write a program that asks for the principal, the interest rate, and the number of times the interest is compounded. It should display a report similar to:<br />
Interest Rate:                  4.25%<br />
Times Compounded:             12<br />
Principal:                  $ 1000.00<br />
Interest:                  $    43.34<br />
Amount in Savings:    $ 1043.34
</p></blockquote>
<p>My solution:</p>
<pre class="brush: cpp;">
/* Chapter 3 Challenge 16
   Written by Kirk Hingsberger
   September 26, 2007
   Interest Earned
*/

#include &lt;cmath&gt;
#include &lt;iomanip&gt;
#include &lt;iostream&gt;
using namespace std;

int main()
{
  float principal, rate, currentBalance, interestAmount;
  int t; // t is number of times interest compounded annually

  cout &lt;&lt; &quot;Please enter the principal amount: &quot;;
  cin &gt;&gt; principal;

  cout &lt;&lt; &quot;\nPlease enter the interest rate: &quot;;
  cin &gt;&gt; rate;

  cout &lt;&lt; &quot;\nPlease enter the number of times interest is compounded annually: &quot;;
  cin &gt;&gt; t;

  currentBalance = principal * pow((1 + rate / t), t);
  interestAmount = currentBalance - principal;

  cout &lt;&lt; left &lt;&lt; setw(20) &lt;&lt; &quot;Interest Rate:&quot; &lt;&lt; right &lt;&lt; setw(9);
  cout &lt;&lt; setprecision(2) &lt;&lt; fixed &lt;&lt; rate &lt;&lt; &quot;%&quot; &lt;&lt; endl;
  cout &lt;&lt; left &lt;&lt; setw(20) &lt;&lt; &quot;Times Compounded:&quot; &lt;&lt; right &lt;&lt; setw(9) &lt;&lt; t &lt;&lt; endl;
  cout &lt;&lt; left &lt;&lt; setw(20) &lt;&lt; &quot;Principal:&quot; &lt;&lt; &quot;$&quot; &lt;&lt; right &lt;&lt; setw(8) &lt;&lt; principal &lt;&lt; endl;
  cout &lt;&lt; left &lt;&lt; setw(20) &lt;&lt; &quot;Interest:&quot; &lt;&lt; &quot;$&quot; &lt;&lt; right &lt;&lt; setw(8) &lt;&lt; interestAmount &lt;&lt; endl;
  cout &lt;&lt; left &lt;&lt; setw(20) &lt;&lt; &quot;Amount in Savings:&quot; &lt;&lt; &quot;$&quot; &lt;&lt; right &lt;&lt; setw(8) &lt;&lt; currentBalance &lt;&lt; endl;

  return 0;
}
</pre>
<p>Here is the capture script I turned in for grading:</p>
<pre class="brush: cpp;">
Script started on Thu 27 Sep 2007 01:25:46 PM MDT
$ cat chap3chlg16.cc
/* Chapter 3 Challenge 16
   Written by Kirk Hingsberger
   September 26, 2007
   Interest Earned
*/

#include &lt;cmath&gt;
#include &lt;iomanip&gt;
#include &lt;iostream&gt;
using namespace std;

int main()
{
  float principal, rate, currentBalance, interestAmount;
  int t; // t is number of times interest compounded annually

  cout &lt;&lt; &quot;Please enter the principal amount: &quot;;
  cin &gt;&gt; principal;

  cout &lt;&lt; &quot;\nPlease enter the interest rate: &quot;;
  cin &gt;&gt; rate;

  cout &lt;&lt; &quot;\nPlease enter the number of times interest is compounded annually: &quot;;
  cin &gt;&gt; t;

  currentBalance = principal * pow((1 + rate / t), t);
  interestAmount = currentBalance - principal;

  cout &lt;&lt; left &lt;&lt; setw(20) &lt;&lt; &quot;Interest Rate:&quot; &lt;&lt; right &lt;&lt; setw(9);
  cout &lt;&lt; setprecision(2) &lt;&lt; fixed &lt;&lt; rate &lt;&lt; &quot;%&quot; &lt;&lt; endl;
  cout &lt;&lt; left &lt;&lt; setw(20) &lt;&lt; &quot;Times Compounded:&quot; &lt;&lt; right &lt;&lt; setw(9) &lt;&lt; t &lt;&lt; endl;
  cout &lt;&lt; left &lt;&lt; setw(20) &lt;&lt; &quot;Principal:&quot; &lt;&lt; &quot;$&quot; &lt;&lt; right &lt;&lt; setw(8) &lt;&lt; principal &lt;&lt; endl;
  cout &lt;&lt; left &lt;&lt; setw(20) &lt;&lt; &quot;Interest:&quot; &lt;&lt; &quot;$&quot; &lt;&lt; right &lt;&lt; setw(8) &lt;&lt; interestAmount &lt;&lt; endl;
  cout &lt;&lt; left &lt;&lt; setw(20) &lt;&lt; &quot;Amount in Savings:&quot; &lt;&lt; &quot;$&quot; &lt;&lt; right &lt;&lt; setw(8) &lt;&lt; currentBalance &lt;&lt; endl;

  return 0;
}
$ g++ -o chap3chlg16 chap3chlg16.cc -s
$ chap3chlg16
Please enter the principal amount: 10000

Please enter the interest rate: .0672

Please enter the number of times interest is compounded annually: 6
Interest Rate:                   0.07%
Times Compounded:             6
Principal:                  $ 10000.00
Interest:                  $    691.09
Amount in Savings:    $ 10691.09
$ exit
exit

Script done on Thu 27 Sep 2007 01:26:57 PM MDT
</pre>


<p>Related posts:<ul><li><a href='http://kirkhings.com/code/c/time-calculator/415/' rel='bookmark' title='Permanent Link: Time Calculator'>Time Calculator</a> <small> photo credit: FABIOLA MEDEIROS- direção de arte This programming...</small></li>
<li><a href='http://kirkhings.com/code/c/monthly-sales-tax/162/' rel='bookmark' title='Permanent Link: Monthly Sales Tax'>Monthly Sales Tax</a> <small> photo credit: mindluge This programming challenge is from an...</small></li>
<li><a href='http://kirkhings.com/code/c/box-office-ticket-sales/159/' rel='bookmark' title='Permanent Link: Box Office Ticket Sales'>Box Office Ticket Sales</a> <small> photo credit: © Natalia Balcerska Photography This programming challenge...</small></li>
<li><a href='http://kirkhings.com/code/c/total-purchase/95/' rel='bookmark' title='Permanent Link: Total Purchase'>Total Purchase</a> <small> photo credit: Phillie Casablanca This programming challenge is from...</small></li>
</ul></p>]]></content:encoded>
			<wfw:commentRss>http://kirkhings.com/code/c/interest-earned/341/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Button-Driven Quotes</title>
		<link>http://kirkhings.com/code/visual-basic-code/button-driven-quotes/352/</link>
		<comments>http://kirkhings.com/code/visual-basic-code/button-driven-quotes/352/#comments</comments>
		<pubDate>Wed, 13 May 2009 03:12:21 +0000</pubDate>
		<dc:creator>Kirk</dc:creator>
				<category><![CDATA[Visual Basic]]></category>
		<category><![CDATA[.Net]]></category>
		<category><![CDATA[academic challenge]]></category>
		<category><![CDATA[visual basic]]></category>

		<guid isPermaLink="false">http://kirkhings.com/?p=352</guid>
		<description><![CDATA[ photo credit: bogenfreund
This programming challenge is from a Visual Basic.Net programming course I took in Spring 2008. The Chapter (1) was titled &#8220;Introduction to Visual Basic .Net 2005&#8243;.
I post these old academic challenges for a few reasons. One is to demonstrate my programming learning, experience, and progression. Another reason is to make sure my [...]


Related posts:<ul><li><a href='http://kirkhings.com/code/visual-basic-code/diner-specials-display/375/' rel='bookmark' title='Permanent Link: Diner Specials Display'>Diner Specials Display</a> <small> photo credit: wEnDaLicious This programming challenge is from a...</small></li>
<li><a href='http://kirkhings.com/code/javascript/three-state-javascript-rollover/312/' rel='bookmark' title='Permanent Link: Three-State JavaScript Rollover'>Three-State JavaScript Rollover</a> <small> photo credit: chimothy27 This programming challenge is from a...</small></li>
<li><a href='http://kirkhings.com/code/javascript/accessible-javascript-rollover-with-three-state-functionality/319/' rel='bookmark' title='Permanent Link: Accessible JavaScript Rollover with Three-State Functionality'>Accessible JavaScript Rollover with Three-State Functionality</a> <small> photo credit: Rhian vK This programming challenge is from...</small></li>
<li><a href='http://kirkhings.com/code/jquery/disable-submit-button-to-prevent-double-submit/170/' rel='bookmark' title='Permanent Link: Disable Submit Button to Prevent Double-Submit'>Disable Submit Button to Prevent Double-Submit</a> <small> photo credit: kevindooley This programming snippet is from the...</small></li>
</ul>]]></description>
			<content:encoded><![CDATA[<div class="borrowedPic"><a href="http://www.flickr.com/photos/28548387@N00/486124675/" title="Descending Memories" target="_blank"><img src="http://farm1.static.flickr.com/187/486124675_f111c90f53.jpg" alt="Descending Memories" border="0" /></a><br /><small><a href="http://creativecommons.org/licenses/by-sa/2.0/" title="Attribution-ShareAlike License" target="_blank"><img src="http://kirkhings.com/wp-content/plugins/photo-dropper/images/cc.png" alt="Creative Commons License" border="0" width="16" height="16" align="absmiddle" /></a> <a href="http://www.photodropper.com/photos/" target="_blank">photo</a> credit: <a href="http://www.flickr.com/photos/28548387@N00/486124675/" title="bogenfreund" target="_blank">bogenfreund</a></small></div>
<p>This programming challenge is from a Visual Basic.Net programming course I took in Spring 2008. The Chapter (1) was titled &#8220;Introduction to Visual Basic .Net 2005&#8243;.</p>
<p>I post these old academic challenges for a few reasons. One is to demonstrate my programming learning, experience, and progression. Another reason is to make sure my code and solutions are indexed by search engines, so that other beginning programmers may get help if they need it.</p>
<blockquote><p>1.3: Write a project that displays four short sayings. When the saying displays on your form, long lines will run off the form if the label&#8217;s AutoSize property is set to True. To wrap text within the label, change the AutoSize property to False and use the sizing handles to make the label large enough.<br />
Make a button for each saying with a descriptive Text property for each, as well as a button to exit the project.<br />
Include a label that holds your name at the bottom of the form. Also, make sure to change the form&#8217;s title bar to something meaningful.<br />
Change the Font properties of the large label to the font and size of your choice.<br />
Make sure the buttons are large enough to hold their entire Text properties.<br />
Follow good naming conventions for object names; include remarks at the top of every procedure and at the top of the file.
</p></blockquote>
<p>My solution code:</p>
<pre class="brush: vb;">
'Assignment 1
'Problem 1.3
'Kirk Hingsberger
'Display four sayings

Public Class quotesForm

    Private Sub exitButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles exitButton.Click
        ' Exits program

        Me.Close()
    End Sub

    Private Sub proofButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles proofButton.Click
        ' Display Proof quote above

        Me.quotesLabel.Text = &quot;I remember the time I was kidnapped and they sent a piece of my finger to my father. He said he wanted more proof.&quot;
    End Sub

    Private Sub argueButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles argueButton.Click
        ' Display Argue quote above

        Me.quotesLabel.Text = &quot;Only a fool argues with a skunk, a mule or the cook.&quot;
    End Sub

    Private Sub upstreamButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles upstreamButton.Click
        ' Display Upstream quote above

        Me.quotesLabel.Text = &quot;Always drink upstream from the herd.&quot;
    End Sub

    Private Sub pmsButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles pmsButton.Click
        ' Display PMS quote above

        Me.quotesLabel.Text = &quot;Do you know why they call it 'PMS'? Because 'Mad Cow Disease' was already taken.&quot;
    End Sub
End Class
</pre>
<p>My solution&#8217;s build screenshot:</p>
<div id="attachment_371" class="wp-caption alignleft" style="width: 410px"><img src="http://kirkhings.com/wp-content/uploads/vb1-3.png" alt="Press a button to get a quote" title="vb1-3" width="400" height="242" class="size-full wp-image-371" /><p class="wp-caption-text">Press a button to get a quote</p></div>


<p>Related posts:<ul><li><a href='http://kirkhings.com/code/visual-basic-code/diner-specials-display/375/' rel='bookmark' title='Permanent Link: Diner Specials Display'>Diner Specials Display</a> <small> photo credit: wEnDaLicious This programming challenge is from a...</small></li>
<li><a href='http://kirkhings.com/code/javascript/three-state-javascript-rollover/312/' rel='bookmark' title='Permanent Link: Three-State JavaScript Rollover'>Three-State JavaScript Rollover</a> <small> photo credit: chimothy27 This programming challenge is from a...</small></li>
<li><a href='http://kirkhings.com/code/javascript/accessible-javascript-rollover-with-three-state-functionality/319/' rel='bookmark' title='Permanent Link: Accessible JavaScript Rollover with Three-State Functionality'>Accessible JavaScript Rollover with Three-State Functionality</a> <small> photo credit: Rhian vK This programming challenge is from...</small></li>
<li><a href='http://kirkhings.com/code/jquery/disable-submit-button-to-prevent-double-submit/170/' rel='bookmark' title='Permanent Link: Disable Submit Button to Prevent Double-Submit'>Disable Submit Button to Prevent Double-Submit</a> <small> photo credit: kevindooley This programming snippet is from the...</small></li>
</ul></p>]]></content:encoded>
			<wfw:commentRss>http://kirkhings.com/code/visual-basic-code/button-driven-quotes/352/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Math Tutor</title>
		<link>http://kirkhings.com/code/c/math-tutor/331/</link>
		<comments>http://kirkhings.com/code/c/math-tutor/331/#comments</comments>
		<pubDate>Tue, 12 May 2009 16:46:07 +0000</pubDate>
		<dc:creator>Kirk</dc:creator>
				<category><![CDATA[C++]]></category>
		<category><![CDATA[academic challenge]]></category>

		<guid isPermaLink="false">http://kirkhings.com/?p=331</guid>
		<description><![CDATA[ photo credit: *Zara
This programming challenge is from an initial C++ programming course I took in Fall 2007. The Chapter (3) was titled &#8220;Expressions and Interactivity&#8221;.
I post these old academic challenges for a few reasons. One is to demonstrate my programming learning, experience, and progression. Another reason is to make sure my code and solutions [...]


Related posts:<ul><li><a href='http://kirkhings.com/code/c/math-tutor-enhanced/417/' rel='bookmark' title='Permanent Link: Math Tutor Enhanced'>Math Tutor Enhanced</a> <small> photo credit: foundphotoslj 4.9: This is a modification of...</small></li>
<li><a href='http://kirkhings.com/code/c/saving-numbers-to-a-file/348/' rel='bookmark' title='Permanent Link: Saving Numbers to a File'>Saving Numbers to a File</a> <small> photo credit: Mykl Roventine This programming challenge is from...</small></li>
<li><a href='http://kirkhings.com/code/c/interest-earned/341/' rel='bookmark' title='Permanent Link: Interest Earned'>Interest Earned</a> <small> photo credit: conorwithonen This programming challenge is from an...</small></li>
<li><a href='http://kirkhings.com/code/c/box-office-ticket-sales/159/' rel='bookmark' title='Permanent Link: Box Office Ticket Sales'>Box Office Ticket Sales</a> <small> photo credit: © Natalia Balcerska Photography This programming challenge...</small></li>
</ul>]]></description>
			<content:encoded><![CDATA[<div class="borrowedPic"><a href="http://www.flickr.com/photos/78364316@N00/459002147/" title="I am just" target="_blank"><img src="http://farm1.static.flickr.com/215/459002147_b46017042e.jpg" alt="I am just" border="0" /></a><br /><small><a href="http://creativecommons.org/licenses/by-sa/2.0/" title="Attribution-ShareAlike License" target="_blank"><img src="http://kirkhings.com/wp-content/plugins/photo-dropper/images/cc.png" alt="Creative Commons License" border="0" width="16" height="16" align="absmiddle" /></a> <a href="http://www.photodropper.com/photos/" target="_blank">photo</a> credit: <a href="http://www.flickr.com/photos/78364316@N00/459002147/" title="*Zara" target="_blank">*Zara</a></small></div>
<p>This programming challenge is from an initial C++ programming course I took in Fall 2007. The Chapter (3) was titled &#8220;Expressions and Interactivity&#8221;.</p>
<p>I post these old academic challenges for a few reasons. One is to demonstrate my programming learning, experience, and progression. Another reason is to make sure my code and solutions are indexed by search engines, so that other beginning programmers may get help if they need it.</p>
<blockquote><p>3.15: Write a program that can be used as a math tutor for a young student. The program should display two random numbers to be added, such as </p>
<pre>
   247
+ 129
------
</pre>
<p>The program should then pause while the student works on the problem. When the student is ready to check the answer, he or she can press a key and the program will display the correct solution, for example:</p>
<pre>
   247
+ 129
------
   376
</pre>
</blockquote>
<p>My solution:</p>
<pre class="brush: cpp;">
/* Chapter 3 Challenge 15
   Written by Kirk Hingsberger
   September 26, 2007
   Math Tutor
*/

#include &lt;iomanip&gt;
#include &lt;cstdlib&gt;
#include &lt;ctime&gt;
#include &lt;iostream&gt;
using namespace std;

int main()
{
  char ch;
  srand(time(0));
  const int SEED = 999;
  int num1, num2, num3;

  num1 = 1 + rand() % SEED;
  num2 = 1 + rand() % SEED;

  cout &lt;&lt; setw(5) &lt;&lt; num1 &lt;&lt; endl;
  cout &lt;&lt; &quot;+ &quot; &lt;&lt; setw(3) &lt;&lt; num2 &lt;&lt; endl;
  cout &lt;&lt; &quot;_____&quot; &lt;&lt; endl;
  num3 = num1 + num2;
  cin.get(ch);
  cout &lt;&lt; setw(5) &lt;&lt; num3 &lt;&lt; endl;

  return 0;
}
</pre>
<p>Here is the capture script I turned in for grading:</p>
<pre class="brush: cpp;">
Script started on Thu 27 Sep 2007 01:24:48 PM MDT
$ cat chap3chlg15.cc
/* Chapter 3 Challenge 15
   Written by Kirk Hingsberger
   September 26, 2007
   Math Tutor
*/

#include &lt;iomanip&gt;
#include &lt;cstdlib&gt;
#include &lt;ctime&gt;
#include &lt;iostream&gt;
using namespace std;

int main()
{
  char ch;
  srand(time(0));
  const int SEED = 999;
  int num1, num2, num3;

  num1 = 1 + rand() % SEED;
  num2 = 1 + rand() % SEED;

  cout &lt;&lt; setw(5) &lt;&lt; num1 &lt;&lt; endl;
  cout &lt;&lt; &quot;+ &quot; &lt;&lt; setw(3) &lt;&lt; num2 &lt;&lt; endl;
  cout &lt;&lt; &quot;_____&quot; &lt;&lt; endl;
  num3 = num1 + num2;
  cin.get(ch);
  cout &lt;&lt; setw(5) &lt;&lt; num3 &lt;&lt; endl;

  return 0;
}
$ g++ -o chap3chlg15 chap3chlg15.cc -s
$ chap3chlg15
  983
+  77
_____
 1060
$ exit
exit

Script done on Thu 27 Sep 2007 01:25:38 PM MDT
</pre>


<p>Related posts:<ul><li><a href='http://kirkhings.com/code/c/math-tutor-enhanced/417/' rel='bookmark' title='Permanent Link: Math Tutor Enhanced'>Math Tutor Enhanced</a> <small> photo credit: foundphotoslj 4.9: This is a modification of...</small></li>
<li><a href='http://kirkhings.com/code/c/saving-numbers-to-a-file/348/' rel='bookmark' title='Permanent Link: Saving Numbers to a File'>Saving Numbers to a File</a> <small> photo credit: Mykl Roventine This programming challenge is from...</small></li>
<li><a href='http://kirkhings.com/code/c/interest-earned/341/' rel='bookmark' title='Permanent Link: Interest Earned'>Interest Earned</a> <small> photo credit: conorwithonen This programming challenge is from an...</small></li>
<li><a href='http://kirkhings.com/code/c/box-office-ticket-sales/159/' rel='bookmark' title='Permanent Link: Box Office Ticket Sales'>Box Office Ticket Sales</a> <small> photo credit: © Natalia Balcerska Photography This programming challenge...</small></li>
</ul></p>]]></content:encoded>
			<wfw:commentRss>http://kirkhings.com/code/c/math-tutor/331/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Monthly Sales Tax</title>
		<link>http://kirkhings.com/code/c/monthly-sales-tax/162/</link>
		<comments>http://kirkhings.com/code/c/monthly-sales-tax/162/#comments</comments>
		<pubDate>Mon, 16 Mar 2009 09:01:10 +0000</pubDate>
		<dc:creator>Kirk</dc:creator>
				<category><![CDATA[C++]]></category>
		<category><![CDATA[academic challenge]]></category>

		<guid isPermaLink="false">http://kirkhings.com/?p=162</guid>
		<description><![CDATA[ photo credit: mindluge
This programming challenge is from an initial C++ programming course I took in Fall 2007. The Chapter (3) was titled &#8220;Expressions and Interactivity&#8221;.
I post these old academic challenges for a few reasons. One is to demonstrate my programming learning, experience, and progression. Another reason is to make sure my code and solutions [...]


Related posts:<ul><li><a href='http://kirkhings.com/code/c/box-office-ticket-sales/159/' rel='bookmark' title='Permanent Link: Box Office Ticket Sales'>Box Office Ticket Sales</a> <small> photo credit: © Natalia Balcerska Photography This programming challenge...</small></li>
<li><a href='http://kirkhings.com/code/c/sales-prediction/73/' rel='bookmark' title='Permanent Link: Sales Prediction'>Sales Prediction</a> <small> photo credit: woodleywonderworks This programming challenge is from an...</small></li>
<li><a href='http://kirkhings.com/code/c/sales-tax/81/' rel='bookmark' title='Permanent Link: Sales Tax'>Sales Tax</a> <small> photo credit: Phillip This programming challenge is from an...</small></li>
<li><a href='http://kirkhings.com/code/c/stadium-seating/138/' rel='bookmark' title='Permanent Link: Stadium Seating'>Stadium Seating</a> <small> photo credit: Daveybot This programming challenge is from an...</small></li>
</ul>]]></description>
			<content:encoded><![CDATA[<div class="borrowedPic"><a href="http://www.flickr.com/photos/16046854@N00/315274981/" title="the art of the cash register" target="_blank"><img src="http://farm1.static.flickr.com/121/315274981_827fa917a0.jpg" alt="the art of the cash register" border="0" /></a><br /><small><a href="http://creativecommons.org/licenses/by/2.0/" title="Attribution License" target="_blank"><img src="http://kirkhings.com/wp-content/plugins/photo-dropper/images/cc.png" alt="Creative Commons License" border="0" width="16" height="16" align="absmiddle" /></a> <a href="http://www.photodropper.com/photos/" target="_blank">photo</a> credit: <a href="http://www.flickr.com/photos/16046854@N00/315274981/" title="mindluge" target="_blank">mindluge</a></small></div>
<p>This programming challenge is from an initial C++ programming course I took in Fall 2007. The Chapter (3) was titled &#8220;Expressions and Interactivity&#8221;.</p>
<p>I post these old academic challenges for a few reasons. One is to demonstrate my programming learning, experience, and progression. Another reason is to make sure my code and solutions are indexed by search engines, so that other beginning programmers may get help if they need it.</p>
<blockquote><p>3.12: A retail company must file a monthly sales tax report listing the sales for the month and the amount of sales tax collected. Write a program that asks for the month, the year, and the total amount collected at the cash register (that is, sales plus sales tax). Assume the state sales tax is 4 percent and the county sales tax is 2 percent.</p>
<p>If the total amount collected is known and the total sales tax is 6 percent, the amount of product sales may be calculated as: S = T / 1.06, where S is the product sales and T is the total income (product sales plus sales tax).</p>
<p>The program should display a report similar to: (output pictured in book, and faithfully reproduced in my programming output.)
</p></blockquote>
<p>My solution:</p>
<pre class="brush: cpp;">
/* Chapter 3 Challenge 12
   Written by Kirk Hingsberger
   September 26, 2007
   Monthly Sales Tax
*/

#include &lt;iomanip&gt;
#include &lt;iostream&gt;
using namespace std;

int main()
{
  const float TAXRATE_STATE = .04;
  const float TAXRATE_COUNTY = .02;
  const float TAXRATE_TOTAL = .06;
  char month[16], year[5];
  float totalCollected, sales, taxsumCounty, taxsumState, taxsumTotal;

  cout &lt;&lt; setprecision(2) &lt;&lt; fixed;

  cout &lt;&lt; &quot;Month and year (separated by a space) you are reporting: &quot; &lt;&lt; endl;
  cin &gt;&gt; month &gt;&gt; year;

  cout &lt;&lt; &quot;What was the total dollar amount collected from register?&quot; &lt;&lt; endl;
  cin &gt;&gt; totalCollected;

  sales = totalCollected / 1.06;
  taxsumCounty = sales * TAXRATE_COUNTY;
  taxsumState = sales * TAXRATE_STATE;
  taxsumTotal = sales * TAXRATE_TOTAL;

  cout &lt;&lt; left &lt;&lt; setw(7) &lt;&lt; &quot;Month: &quot; &lt;&lt; setw(13) &lt;&lt;  month;
  cout &lt;&lt; setw(5) &lt;&lt; &quot;Year: &quot; &lt;&lt; setw(5) &lt;&lt; year &lt;&lt; endl;
  cout &lt;&lt; &quot;--------------------&quot; &lt;&lt; endl;
  cout &lt;&lt; left &lt;&lt; setw(20) &lt;&lt; &quot;Total Collected:&quot;;
  cout &lt;&lt; &quot;$&quot; &lt;&lt; right &lt;&lt; setw(9) &lt;&lt; totalCollected &lt;&lt; endl;
  cout &lt;&lt; left &lt;&lt; setw(20) &lt;&lt; &quot;Sales:&quot;;
  cout &lt;&lt; &quot;$&quot; &lt;&lt; right &lt;&lt; setw(9) &lt;&lt; sales &lt;&lt; endl;
  cout &lt;&lt; left &lt;&lt; setw(20) &lt;&lt; &quot;County Sales Tax:&quot;;
  cout &lt;&lt; &quot;$&quot; &lt;&lt; right &lt;&lt; setw(9) &lt;&lt; taxsumCounty &lt;&lt; endl;
  cout &lt;&lt; left &lt;&lt; setw(20) &lt;&lt; &quot;State Sales Tax:&quot;;
  cout &lt;&lt; &quot;$&quot; &lt;&lt; right &lt;&lt; setw(9) &lt;&lt; taxsumState &lt;&lt; endl;
  cout &lt;&lt; left &lt;&lt; setw(20) &lt;&lt; &quot;Total Sales Tax:&quot;;
  cout &lt;&lt; &quot;$&quot; &lt;&lt; right &lt;&lt; setw(9) &lt;&lt; taxsumTotal &lt;&lt; endl;

  return 0;
}
</pre>
<p>Here is the capture script I turned in for grading:</p>
<pre class="brush: cpp;">
Script started on Thu 27 Sep 2007 01:23:52 PM MDT
$ cat chap3chlg12.cc
/* Chapter 3 Challenge 12
   Written by Kirk Hingsberger
   September 26, 2007
   Monthly Sales Tax
*/

#include &lt;iomanip&gt;
#include &lt;iostream&gt;
using namespace std;

int main()
{
  const float TAXRATE_STATE = .04;
  const float TAXRATE_COUNTY = .02;
  const float TAXRATE_TOTAL = .06;
  char month[16], year[5];
  float totalCollected, sales, taxsumCounty, taxsumState, taxsumTotal;

  cout &lt;&lt; setprecision(2) &lt;&lt; fixed;

  cout &lt;&lt; &quot;Month and year (separated by a space) you are reporting: &quot; &lt;&lt; endl;
  cin &gt;&gt; month &gt;&gt; year;

  cout &lt;&lt; &quot;What was the total dollar amount collected from register?&quot; &lt;&lt; endl;
  cin &gt;&gt; totalCollected;

  sales = totalCollected / 1.06;
  taxsumCounty = sales * TAXRATE_COUNTY;
  taxsumState = sales * TAXRATE_STATE;
  taxsumTotal = sales * TAXRATE_TOTAL;

  cout &lt;&lt; left &lt;&lt; setw(7) &lt;&lt; &quot;Month: &quot; &lt;&lt; setw(13) &lt;&lt;  month;
  cout &lt;&lt; setw(5) &lt;&lt; &quot;Year: &quot; &lt;&lt; setw(5) &lt;&lt; year &lt;&lt; endl;
  cout &lt;&lt; &quot;--------------------&quot; &lt;&lt; endl;
  cout &lt;&lt; left &lt;&lt; setw(20) &lt;&lt; &quot;Total Collected:&quot;;
  cout &lt;&lt; &quot;$&quot; &lt;&lt; right &lt;&lt; setw(9) &lt;&lt; totalCollected &lt;&lt; endl;
  cout &lt;&lt; left &lt;&lt; setw(20) &lt;&lt; &quot;Sales:&quot;;
  cout &lt;&lt; &quot;$&quot; &lt;&lt; right &lt;&lt; setw(9) &lt;&lt; sales &lt;&lt; endl;
  cout &lt;&lt; left &lt;&lt; setw(20) &lt;&lt; &quot;County Sales Tax:&quot;;
  cout &lt;&lt; &quot;$&quot; &lt;&lt; right &lt;&lt; setw(9) &lt;&lt; taxsumCounty &lt;&lt; endl;
  cout &lt;&lt; left &lt;&lt; setw(20) &lt;&lt; &quot;State Sales Tax:&quot;;
  cout &lt;&lt; &quot;$&quot; &lt;&lt; right &lt;&lt; setw(9) &lt;&lt; taxsumState &lt;&lt; endl;
  cout &lt;&lt; left &lt;&lt; setw(20) &lt;&lt; &quot;Total Sales Tax:&quot;;
  cout &lt;&lt; &quot;$&quot; &lt;&lt; right &lt;&lt; setw(9) &lt;&lt; taxsumTotal &lt;&lt; endl;

  return 0;
}
$ g++ -o chap3chlg12 chap3chlg12.cc -s
$ chap3chlg12
Month and year (separated by a space) you are reporting:
October 2009
What was the total dollar amount collected from register?
10000
Month: October      Year: 2009
--------------------
Total Collected:    $ 10000.00
Sales:              $  9433.96
County Sales Tax:   $   188.68
State Sales Tax:    $   377.36
Total Sales Tax:    $   566.04
$ exit
exit

Script done on Thu 27 Sep 2007 01:24:40 PM MDT
</pre>


<p>Related posts:<ul><li><a href='http://kirkhings.com/code/c/box-office-ticket-sales/159/' rel='bookmark' title='Permanent Link: Box Office Ticket Sales'>Box Office Ticket Sales</a> <small> photo credit: © Natalia Balcerska Photography This programming challenge...</small></li>
<li><a href='http://kirkhings.com/code/c/sales-prediction/73/' rel='bookmark' title='Permanent Link: Sales Prediction'>Sales Prediction</a> <small> photo credit: woodleywonderworks This programming challenge is from an...</small></li>
<li><a href='http://kirkhings.com/code/c/sales-tax/81/' rel='bookmark' title='Permanent Link: Sales Tax'>Sales Tax</a> <small> photo credit: Phillip This programming challenge is from an...</small></li>
<li><a href='http://kirkhings.com/code/c/stadium-seating/138/' rel='bookmark' title='Permanent Link: Stadium Seating'>Stadium Seating</a> <small> photo credit: Daveybot This programming challenge is from an...</small></li>
</ul></p>]]></content:encoded>
			<wfw:commentRss>http://kirkhings.com/code/c/monthly-sales-tax/162/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
