Sales Prediction

This programming challenge is from an initial C++ programming course I took in Fall 2007. The Chapter (2) was titled “Introduction to C++”.

2.2: The East Coast sales division of a company generates 62% of total sales. Based on that percentage, write a program that predicts how much the East Coast division will generate if the company has $4.6 million in sales this year.

My solution:

/* Chapter 2 Challenge 2
Written by Kirk Hingsberger
Sept 12, 2007
Purpose: Sales Prediction using hard-coded figures
*/

#include
using namespace std;

int main()
{
float totalSales = 4600000;
float divEastPrcnt = .62;
float divEastAmount = totalSales * divEastPrcnt ;

cout << "When the company generates $" << totalSales << endl;
cout << "in sales this year, the East Coast sales " << endl;
cout << "division will generate $" << divEastAmount << endl;
cout << "of that." << endl;

return 0;
}

When this program ran, the numbers output in scientific notation. Our professor did not want us to worry about converting numeric formats in this challenge.

Here is the capture script I turned in for grading:

Script started on Thu 13 Sep 2007 10:08:35 AM MDT
$ cat chap2chlg2.cc
/* Chapter 2 Challenge 2
Written by Kirk Hingsberger
Sept 12, 2007
Purpose: Sales Prediction using hard-coded figures
*/

#include
using namespace std;

int main()
{
float totalSales = 4600000;
float divEastPrcnt = .62;
float divEastAmount = totalSales * divEastPrcnt ;

cout << “When the company generates $” << totalSales << endl;
cout << “in sales this year, the East Coast sales ” << endl;
cout << “division will generate $” << divEastAmount << endl;
cout << “of that.” << endl;

return 0;
}
$ g++ -o chap2chlg2 chap2chlg2.cc -s
$ chap2chlg2
When the company generates $4.6e+06
in sales this year, the East Coast sales
division will generate $2.852e+06
of that.
$ exit
exit

Script done on Thu 13 Sep 2007 10:09:11 AM MDT

  • Share/Bookmark




Leave a Reply