My C plus plus Website
My Writing and Programs

Home

About Me | My Writing and Programs | Classic Cars | Related Links | Contact Me | More C plus plus Links | New Links

My creative side...

On this page, I'll show off some of my own work and the programs of others. For example, I might include a short story I've written, a program, or an essay I did for a class that I'm especially proud of.

Click on the bird to learn about the history of C++.

bird

Programming Problem:
Showing Mr. Young What 4
Create a C++ program, email the pseudocode, and demonstrate the program to Mr. Young. This program should have the following characteristics:
-Input statements to read values into the program.
-Appropriate prompting messages for interactions with the user.
-An appropriate non-interactive segment.
-Use data files for input, and output.
-Have non-boring output.
-Be self-documenting.
Deal with the Rule of 72.

My answer:

#include <iomanip.h>
#include <fstream.h>
#include <stdlib.h>
void clrscr(); //this function will clear the screen but still display the data at the top.
//This program uses input and output files,the rule of 72, and keyboard input from the user
//Joshua Johnson
float fvalue=0;
float ivalue=0; //The starting value
float interest=0; //the amount of money gained each year.
float rule;
ofstream out;
int year;

//>>>>>>>>>>>>>>>>>>>>
//MAIN
//<<<<<<<<<<<<<<<<<<<<

void main() //I am using void main because I am not returning a value
{

cout<<" THE RULE OF 72"<<endl;
cout<<"This program will calculate the year in which your investment will double."<<endl<<endl;
ifstream in;
in.open("72 Output.txt");
in.close();
cout<<"Enter the current year: ";
cin>>year;// takes the variable that the user enters in and gives the value to year
clrscr(); // clears the screen
cout<<"Enter your current deposit amount: ";
cin>>ivalue;// takes the variable that the user enters in and gives the value to ivalue
clrscr(); // clears the screen
cout<<"Enter the yearly interest rate in a percent out of 100: ";
cin>>interest;
interest=(interest/100);
clrscr(); // clears the screen

rule=72/(interest*100);
out.open("72 Output.txt");
cout<<"According to the rule of 72 your money would double in the year: "<<year+rule<<endl;
cout<<"program terminated"<<endl;
}

// this allows me to clear the screen
void clrscr()
{
system("CLS");
cout<<"Current year: "<<year<<endl;
cout<<"Current value: "<<ivalue<<endl;
cout<<"The amount of Yearly interest: "<<interest<<endl<<endl<<endl;
if (interest!=0)
{
out.open("72 Output.txt");
out<<"Current year: "<<year<<endl;
out<<"Current investment value: "<<ivalue<<endl;
out<<"The amount of yearly interest: "<<interest<<endl<<endl<<endl;
out.close();
}


}