
Please help the out keeps printing twice
#include
#include
#include
#include
#include
using namespace std;
/**
* Function to calculate the future value and return the same
*/
double calculateFutureValue(double presentValue, double
interestRate, int months)
{
double futureValue = (double)presentValue * pow((1 +
interestRate), months);
return futureValue;
}
/**
* Function to read the input file and assign the value to the
variables
*/
unsigned int readfile(ifstream &inF, double &presentValue,
double &interestRate, int &months)
{
inF >> presentValue;
inF >> interestRate;
inF >> months;
if (presentValue <= 0 || interestRate <= 0 ||
months <= 0)
{
return 2;
}
else if (!(presentValue <= 0 || interestRate <=
0 || months <= 0))
return 1;
else
{
if (inF.eof())
return 0;
}
}
/**
* Function to write data to file
*/
void write2File(ofstream &of, double futureValue, double
presentValue, double interestRate, int months)
{
of << futureValue << "\t" <<
presentValue << "\t" << interestRate << "\t"
<< months << "\n";
}
// main function
int main(void)
{
std::setprecision(2);
string infile;
cin >> infile;
ifstream inF;
inF.open(infile.c_str());
if (!inF)
{
cout << "File \"" <<
infile << "\" could not be opened\n";
return -1;
}
string outfile = "output.xls";
ofstream of;
of.open(outfile.c_str());
if (!of)
{
cout << "Error in creating the
output file" << endl;
return -1;
}
of << "Future Value\tPresent Value\tMonthly
Interest\tMonths\n"; // printing header to output file
double futureValue;
double presentValue;
double interestRate;
int months;
of << fixed << setprecision(2); // to
print 2 places after decimal into file
while (!inF.eof()) // looping untill end of file
{
int returnVal = readfile(inF,
presentValue, interestRate, months);
if (returnVal == 2)
{
std::setprecision(2);
cout <<
presentValue << "\t " << interestRate << "\t "
<< months << endl;
cout << "One
or more of the above values are not greater than zero" <<
endl;
}
else if (returnVal == 1)
{
futureValue =
calculateFutureValue(presentValue, interestRate / 100,
months);
write2File(of,
futureValue, presentValue, interestRate, months);
}
}
inF.close();
of.close();
return 1;
}
//Changes are in bold
//main.cpp
//include header files
#include<iostream>
#include<string>
#include<iomanip>
#include<math.h>
#include<fstream>
using namespace std;
/**
* Function to calculate the future value and return the same
*/
double calculateFutureValue(double presentValue, double
interestRate, int months)
{
double futureValue = (double)presentValue * pow((1 +
interestRate), months);
return futureValue;
}
/**
* Function to read the input file and assign the value to the
variables
*/
unsigned int readfile(ifstream &inF, double &presentValue,
double &interestRate, int &months)
{
inF >> presentValue;
inF >> interestRate;
inF >> months;
if (presentValue <= 0 || interestRate <= 0 ||
months <= 0)
return 2;
else if (!(presentValue <= 0 || interestRate <=
0 || months <= 0))
return 1;
else if (inF.eof())
return 0;
}
/**
* Function to write data to file
*/
void write2File(ofstream &of, double futureValue, double
presentValue, double interestRate, int months)
{
of << futureValue << "\t" <<
presentValue << "\t" << interestRate << "\t"
<< months << "\n";
}
// main function
int main(void)
{
std::setprecision(2);
string infile;
cin >> infile;
ifstream inF;
inF.open(infile.c_str());
if (!inF)
{
cout << "File \"" <<
infile << "\" could not be opened\n";
system("pause");
return -1;
}
string outfile = "output.xls";
ofstream of;
of.open(outfile.c_str());
if (!of)
{
cout << "Error in creating
the output file" << endl;
return -1;
}
of << "Future Value\tPresent Value\tMonthly
Interest\tMonths\n"; // printing header to output file
double futureValue;
double presentValue;
double interestRate;
int months;
of << fixed << setprecision(2);
// to print 2 places after decimal into file
while (!inF.eof()) // looping untill end of
file
{
int returnVal = readfile(inF,
presentValue, interestRate, months);
if (returnVal == 2)
{
//use
fixed <<setprecision(2) before printing
cout <<
fixed<<setprecision(2)<<presentValue <<
"\t " << interestRate << "\t " << months <<
endl;
cout <<
"One or more of the above values are not greater than zero"
<< endl;
}
else if (returnVal == 1)
{
futureValue =
calculateFutureValue(presentValue, interestRate / 100,
months);
write2File(of,
futureValue, presentValue, interestRate, months);
}
}
inF.close();
of.close();
system("pause");
return 1;
}
---------------------------------------------------------------------------
input3.txt
-10000 1.10 48
10000 -1.00 12
10000 1.10 0
0.00 0.00 0
---------------------------------------------------------------------------
Sample Output:

---------------------------------------------------------------------------
input3.txt (chagne input file data)
10000 0.42 48
---------------------------------------------------------------------------
Sample output:

Excel screen shot:

Please help the out keeps printing twice #include #include #include #include #include using namespace std; /**...
This is the creatList and printList function
#include <iostream>
#include <fstream>
using namespace std;
struct nodeType
{
int info;
nodeType *link;
nodeType *next;
double value;
};
void createList(nodeType*& first, nodeType*& last,
ifstream& inf);
void printList(nodeType* first);
int main()
{
nodeType *first, *last;
int num;
ifstream infile;
infile.open("InputIntegers.txt");
createList(first, last, infile);
printList(first);
infile.close();
system("pause");
return 0;
}
void createList(nodeType*& first, nodeType*& last,
ifstream& infile)
{
int number;...
#include <iostream> #include <fstream> using namespace std; //constants const int CAP = 100; //function prototypes bool openFile(ifstream &); void readData(ifstream &, int [], int &); void printData(const int [], int); void sum(const int[], int); void removeItem(int[], int &, int); int main() { ifstream inFile; int list[CAP], size = 0; if (!openFile(inFile)) { cout << "Program terminating!! File not found!" << endl; return -1; } //read the data from the file readData(inFile, list, size); inFile.close(); cout << "Data in file:" <<...
#include <iostream> #include <vector> #include <iomanip> using namespace std; int main() { const int NUM_ITEMS = 8; vector <double> inverse(NUM_ITEMS); int j; double temp; for (int i = 0; i < NUM_ITEMS; i++) { inverse.at(i) = 1 / (i + 1.0); } cout << fixed << setprecision(2); cout << "Original vector..." << endl; for (int i = 0; i < NUM_ITEMS; i++) { cout << inverse.at(i) << " "; } cout << endl; cout << "Reversed vector..." << endl; for...
//Need help ASAP in c++ please. Appreciate it! Thank you!! //This is the current code I have. #include <iostream> #include <sstream> #include <iomanip> using namespace std; class googlePlayApp { private: string name; double rating; int numInstalls; int numReviews; double price; public: googlePlayApp(string, double, int, int, double); ~ googlePlayApp(); googlePlayApp(); string getName(); double getRating(); int getNumInstalls(); int getNumReviews(); string getPrice(); void setName(string); void setRating(double); void setNumInstalls(int); void setNumReviews(int); void setPrice(double); }; googlePlayApp::googlePlayApp(string n, double r, int ni, int nr, double pr)...
PLEASE HELP WITH THE FIX ME'S #include #include #include #include "CSVparser.hpp" using namespace std; //============================================================================ // Global definitions visible to all methods and classes //============================================================================ // forward declarations double strToDouble(string str, char ch); // define a structure to hold bid information struct Bid { string bidId; // unique identifier string title; string fund; double amount; Bid() { amount = 0.0; } }; //============================================================================ // Linked-List class definition //============================================================================ /** * Define a class containing data members and methods to *...
4) What is the output if the input istom - Sawyer? #include <iostream> using namespace std; int main() { string playerName; cout << "Enter name"; cin >> playerName; cout << endl « playerName; return 0; } a. Tom - Sawyer b. Tom Sawyer c. Tom d. Sawyer 5) Which XXX generates "Adam is 30 years old." as the output? #include <iostream> using namespace std; int main() { string name = "Adam"; int age = 30; XXX return 0; } a....
I NEED A PSEUDOCODE ALGORITHM FOR THIS CODE PLEASE C++: #include #include #include #include using namespace std; int NumOfEmployees(); int TotDaysAbsent(int); double AverageAbsent(int, int); int main() { cout << endl << "Calculate the average number of days a company's employees are absent." << endl << endl; int numOfEmployees = NumOfEmployees(); TotDaysAbsent(numOfEmployees); return 0; } int NumOfEmployees() { int numOfEmployees = 0; cout << "Please enter the number of employees in the company: "; cin >> numOfEmployees; while(numOfEmployees <= 0) {...
please help me fix the error in here #include<iostream> #include <string> using namespace std; string getStudentName(); double getNumberExams(); double getScoresAndCalculateTotal(double E); double calculateAverage(double n, double t); char determineLetterGrade(); void displayAverageGrade(); int main() { string StudentName; double NumberExam, Average, ScoresAndCalculateTotal; char LetterGrade; StudentName = getStudentName(); NumberExam = getNumberExams(); ScoresAndCalculateTotal= getScoresAndCalculateTotal(NumberExam); Average = calculateAverage(NumberExam, ScoresAndCalculateTotal); return 0; } string getStudentName() { string StudentName; cout << "\n\nEnter Student Name:"; getline(cin, StudentName); return StudentName; } double getNumberExams() { double NumberExam; cout << "\n\n Enter...
#include <iostream> #include <cmath> #include <iomanip> #include <cstdlib> using namespace std; bool isInt (double value) { double dummy; return bool(modf(value, &dummy) == 0); } double sqr(double value) { return value * value; } double calcFrictionFactor(double R, double D, double epsilon) { const double BlasiusCoefficient = 0.3164; double f_old, f_new; f_new = BlasiusCoefficient * pow(R, -0.25); // loop until our two values are within 0.000001 of each other do { f_old = f_new; // previous guess is now the old one...
This is C++ code for parking fee management program #include <iostream> #include <iomanip> using namespace std; void input(char& car, int& ihour,int& imin, int& ohour, int& omin); void time(char car, int ihour, int imin, int ohour, int omin, int& phour, int& pmin, int& round, double& total); void parkingCharge (char car, int round, double& total); void print(char car, int ihour, int imin, int ohour, int omin, int phour, int pmin, int round, double total); int main() { char car; int ihour; int...