Friday, December 5, 2014

C++

C++

May 2013.  About this time I met a university C++ programming student in the university library I have been visiting.  I found out from him that the kid's game Minecraft was written in Java, when he mentioned it to me.

He was a Computer Science major and he told me he wanted to be an expert in C++ because it was the best language in the world.  That got me to thinking I should learn C++ also after learning Java. And that's how I chose C++ to be my second language, rather than the other option of C or Visual Basic.

Here's a C++ program I wrote 8 months after that meeting.  I was working as a programming tutor in the college I was attending after my professor asked me to tutor.  He actually asked me to be a tutor after taking his Beginning Java class, but I was too busy with my own full-time classes, to get around to applying for the position.

I used this C++ program to tutor a Beginning C++ student who wanted to know what's really happening inside a C++ program.

/*
Program that prints bill receipt for customer with
amount of purchase
amount of tax
amount of total bill.
Output: print total bill.
*/

#include <iostream>
#include <iomanip>

using namespace std;

//Start program.
int main()
{
    //Declare variables.
    double purchaseAmount;
    double tax;
    double totalBill;

    //Ask user.
    cout << "Enter amount of purchase: $";

    //Input statement.
    cin >> purchaseAmount;

    //Calculate tax.
    tax = purchaseAmount * 0.20;

    //Calculate total bill.
    totalBill = purchaseAmount + tax;

    //Output statement.
    cout << "\nTotal Bill: " << "$"
            << setprecision(2) << fixed << totalBill;

    return 0;
}
//End program.

Happy computing!

John Sindayen

No comments:

Post a Comment