<?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; C++</title>
	<atom:link href="http://kirkhings.com/tag/c/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>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>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>
		<item>
		<title>Box Office Ticket Sales</title>
		<link>http://kirkhings.com/code/c/box-office-ticket-sales/159/</link>
		<comments>http://kirkhings.com/code/c/box-office-ticket-sales/159/#comments</comments>
		<pubDate>Sun, 15 Mar 2009 09:51:16 +0000</pubDate>
		<dc:creator>Kirk</dc:creator>
				<category><![CDATA[C++]]></category>
		<category><![CDATA[academic challenge]]></category>

		<guid isPermaLink="false">http://kirkhings.com/?p=159</guid>
		<description><![CDATA[ photo credit: © Natalia Balcerska Photography
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 [...]


Related posts:<ul><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/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/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/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/82473454@N00/25134478/" title="Alexisonfire Tickets" target="_blank"><img src="http://farm1.static.flickr.com/23/25134478_1fec870183.jpg" alt="Alexisonfire Tickets" 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/82473454@N00/25134478/" title="© Natalia Balcerska Photography" target="_blank">© Natalia Balcerska Photography</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.5: A movie theater only keeps a percentage of the revenue earned from ticket sales. The remainder goes to the movie distributor. Write a program that calculates a theater&#8217;s gross and net box office profit for a night. The program should ask for the name of the movie, and how many adult and child tickets were sold. (The price of an adult ticket is $6.00 and a child&#8217;s ticket is $3.00.) It should display a report similar to the example (pictured in book, faithfully recreated in my programming example). Assume the theater keeps 20% of the gross box office profit.
</p></blockquote>
<p>My solution:</p>
<p>/* Chapter 3 Challenge 5<br />
   Written by Kirk Hingsberger<br />
   September 26, 2007<br />
   Box Office<br />
*/</p>
<p>#include <iomanip><br />
#include <cstdlib><br />
#include <iostream><br />
using namespace std;</p>
<p>int main()<br />
{<br />
  char movieTitle[50];<br />
  const float PRICE_ADULT = 6.0;<br />
  const float PRICE_KID = 3.0;<br />
  const float REV_THEATER = .2;<br />
  const float REV_DISTRIBUTOR = .8;<br />
  int soldAdult, soldKid;<br />
  float grossAdult, grossKid;<br />
  float profitGross, profitNet, royalty;</p>
<p>  cout << "What was the movie name?" << endl;<br />
  cin.getline(movieTitle, 50);</p>
<p>  cout << "How many adult tickets were sold?" << endl;<br />
  cin >> soldAdult;<br />
  cout << "How many kid tickets were sold?" << endl;<br />
  cin >> soldKid;</p>
<p>  cout << setprecision(2) << fixed;</p>
<p>  grossAdult = soldAdult * PRICE_ADULT;<br />
  grossKid = soldKid * PRICE_KID;</p>
<p>  profitGross = grossAdult + grossKid;<br />
  profitNet = profitGross * REV_THEATER;<br />
  royalty = profitGross * REV_DISTRIBUTOR;</p>
<p>  cout << left << setw(32) << "Movie Name: ";<br />
  cout <<  setw(50) <<  movieTitle << endl;</p>
<p>  cout << left << setw(32) << "Adult Tickets Sold: ";<br />
  cout << "   " << setw(10) <<  soldAdult << endl;</p>
<p>  cout << setw(32) << "Child Tickets Sold: ";<br />
  cout << "   " << setw(10) << soldKid << endl;</p>
<p>  cout << setw(32) << "Gross Box Office Profit: ";<br />
  cout << right << setw(1) << "$" << setw(8) << profitGross << endl;</p>
<p>  cout << left << setw(32) << "Net Box Office Profit: ";<br />
  cout << right << setw(1) << "$" << setw(8) << profitNet << endl;</p>
<p>  cout << left << setw(32) << "Amount Paid to Distributor: ";<br />
  cout << right << setw(1) << "$" << setw(8) << royalty << endl;</p>
<p>  return 0;<br />
}</p>
<p>Here is the capture script I turned in for grading:</p>
<p>Script started on Thu 27 Sep 2007 01:22:56 PM MDT<br />
$ cat chap3chlg5.cc<br />
/* Chapter 3 Challenge 5<br />
   Written by Kirk Hingsberger<br />
   September 26, 2007<br />
   Box Office<br />
*/</p>
<p>#include <iomanip><br />
#include <cstdlib><br />
#include <iostream><br />
using namespace std;</p>
<p>int main()<br />
{<br />
  char movieTitle[50];<br />
  const float PRICE_ADULT = 6.0;<br />
  const float PRICE_KID = 3.0;<br />
  const float REV_THEATER = .2;<br />
  const float REV_DISTRIBUTOR = .8;<br />
  int soldAdult, soldKid;<br />
  float grossAdult, grossKid;<br />
  float profitGross, profitNet, royalty;</p>
<p>  cout << "What was the movie name?" << endl;<br />
  cin.getline(movieTitle, 50);</p>
<p>  cout << "How many adult tickets were sold?" << endl;<br />
  cin >> soldAdult;<br />
  cout << "How many kid tickets were sold?" << endl;<br />
  cin >> soldKid;</p>
<p>  cout << setprecision(2) << fixed;</p>
<p>  grossAdult = soldAdult * PRICE_ADULT;<br />
  grossKid = soldKid * PRICE_KID;</p>
<p>  profitGross = grossAdult + grossKid;<br />
  profitNet = profitGross * REV_THEATER;<br />
  royalty = profitGross * REV_DISTRIBUTOR;</p>
<p>  cout << left << setw(32) << &#8220;Movie Name: &#8220;;<br />
  cout <<  setw(50) <<  movieTitle << endl;</p>
<p>  cout << left << setw(32) << &#8220;Adult Tickets Sold: &#8220;;<br />
  cout << &#8221;   &#8221; << setw(10) <<  soldAdult << endl;</p>
<p>  cout << setw(32) << &#8220;Child Tickets Sold: &#8220;;<br />
  cout << &#8221;   &#8221; << setw(10) << soldKid << endl;</p>
<p>  cout << setw(32) << &#8220;Gross Box Office Profit: &#8220;;<br />
  cout << right << setw(1) << &#8220;$&#8221; << setw(8) << profitGross << endl;</p>
<p>  cout << left << setw(32) << &#8220;Net Box Office Profit: &#8220;;<br />
  cout << right << setw(1) << &#8220;$&#8221; << setw(8) << profitNet << endl;</p>
<p>  cout << left << setw(32) << &#8220;Amount Paid to Distributor: &#8220;;<br />
  cout << right << setw(1) << &#8220;$&#8221; << setw(8) << royalty << endl;</p>
<p>  return 0;<br />
}<br />
$ g++ -o chap3chlg5 chap3chlg5.cc -s<br />
$ chap3chlg5<br />
What was the movie name?<br />
Gone with the Wind<br />
How many adult tickets were sold?<br />
100<br />
How many kid tickets were sold?<br />
200<br />
Movie Name:                     Gone with the Wind<br />
Adult Tickets Sold:                100<br />
Child Tickets Sold:                200<br />
Gross Box Office Profit:        $ 1200.00<br />
Net Box Office Profit:          $  240.00<br />
Amount Paid to Distributor:     $  960.00<br />
$ exit<br />
exit</p>
<p>Script done on Thu 27 Sep 2007 01:23:40 PM MDT</p>


<p>Related posts:<ul><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/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/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/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/box-office-ticket-sales/159/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Test Average</title>
		<link>http://kirkhings.com/code/c/test-average/156/</link>
		<comments>http://kirkhings.com/code/c/test-average/156/#comments</comments>
		<pubDate>Sat, 14 Mar 2009 09:43:35 +0000</pubDate>
		<dc:creator>Kirk</dc:creator>
				<category><![CDATA[C++]]></category>
		<category><![CDATA[academic challenge]]></category>

		<guid isPermaLink="false">http://kirkhings.com/?p=156</guid>
		<description><![CDATA[ photo credit: ccarlstead
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/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/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/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/distance-per-tank-of-gas/97/' rel='bookmark' title='Permanent Link: Distance per Tank of Gas'>Distance per Tank of Gas</a> <small> photo credit: billaday This programming challenge is from an...</small></li>
</ul>]]></description>
			<content:encoded><![CDATA[<div class="borrowedPic"><a href="http://www.flickr.com/photos/27087959@N00/359572656/" title="Writing Exams" target="_blank"><img src="http://farm1.static.flickr.com/123/359572656_51a00dc2a6.jpg" alt="Writing Exams" 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/27087959@N00/359572656/" title="ccarlstead" target="_blank">ccarlstead</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.3: Write a program that asks for five test scores. The program should calculate the average test score and display it. The number displayed should be formatted in fixed-point notation, with one decimal point of precision.
</p></blockquote>
<p>My solution:</p>
<p>/* Chapter 3 Challenge 3<br />
   Written by Kirk Hingsberger<br />
   September 26, 2007<br />
   Test Average<br />
*/</p>
<p>#include <iomanip><br />
#include <iostream><br />
using namespace std;</p>
<p>int main()<br />
{<br />
  float test1,test2,test3,test4,test5;<br />
  float avg;</p>
<p>  cout << "Please enter five test scores, each separated by a space." << endl;<br />
  cin >> test1 >> test2 >> test3 >> test4 >> test5;<br />
  avg = (test1 + test2 + test3 + test4 + test5) / 5.0;</p>
<p>  cout << "The average of your five test scores is ";<br />
  cout << setprecision(1) << fixed << avg << endl;</p>
<p>  return 0;<br />
}</p>
<p>Here is the capture script I turned in for grading:</p>
<p>Script started on Thu 27 Sep 2007 01:21:11 PM MDT<br />
$ cat chap3chlg3.cc<br />
/* Chapter 3 Challenge 3<br />
   Written by Kirk Hingsberger<br />
   September 26, 2007<br />
   Test Average<br />
*/</p>
<p>#include <iomanip><br />
#include <iostream><br />
using namespace std;</p>
<p>int main()<br />
{<br />
  float test1,test2,test3,test4,test5;<br />
  float avg;</p>
<p>  cout << "Please enter five test scores, each separated by a space." << endl;<br />
  cin >> test1 >> test2 >> test3 >> test4 >> test5;<br />
  avg = (test1 + test2 + test3 + test4 + test5) / 5.0;</p>
<p>  cout << &#8220;The average of your five test scores is &#8220;;<br />
  cout << setprecision(1) << fixed << avg << endl;</p>
<p>  return 0;<br />
}<br />
$ g++ -o chap3chlg3 chap3chlg3.cc -s<br />
$ chap3chlg3<br />
Please enter five test scores, each separated by a space.<br />
76<br />
67 67 67 67<br />
The average of your five test scores is 68.8<br />
$ exit<br />
exit</p>
<p>Script done on Thu 27 Sep 2007 01:22:07 PM MDT</p>


<p>Related posts:<ul><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/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/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/distance-per-tank-of-gas/97/' rel='bookmark' title='Permanent Link: Distance per Tank of Gas'>Distance per Tank of Gas</a> <small> photo credit: billaday This programming challenge is from an...</small></li>
</ul></p>]]></content:encoded>
			<wfw:commentRss>http://kirkhings.com/code/c/test-average/156/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
