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)...
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....
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 *...
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...
Thank you! /*Lab 8 : Practicing functions and arrays Purpose: */ #include<iostream> #include<fstream> using namespace std; int read_function(int array[], int, int); int main() { int array[300], numba; read_function(array[300]); cout << "Enter a whole number between 2-20: " << endl; cin >> numba; read_function(numba); return 0; } int read_funtion (int arr[300], int num, int Values) { int sum=0; ifstream array_file; array_file.open("Lab8.dat"); for(int i=0; i < 300; i++) { array_file >> arr[i]; cout << arr[i]; sum += i; } cout << sum;...
#include <iostream> using namespace std; const int SIZE = 10; void displayGreaterThan(int[], int); void displaySmallerThan(int[],int); void displayArrayContent(int[]); void displayLargestValue(int[]); void displaySmallestValue(int[]); int main(){ int number; int numbers[SIZE] = {9,1,90,98,53,22,76,29,37,65}; cout <<"Enter a number: "; cin >> number; cout << endl; displayGreaterThan(numbers,number); cout << endl; displaySmallerThan(numbers,number); cout << endl; displayArrayContent(numbers); cout << endl; displayLargestValue(numbers); cout << endl; displaySmallestValue(numbers); cout << endl; return 0; } void displayGreaterThan(int value[],int num){ cout << " All larger value(s)than" <<...
#include <iostream> #include <chrono> using namespace std; double improvedPow(double x, int y) { // To be implemented by you } int main() { cout << "To calculate x^y ..." << endl; double x; int y; cout << "Please enter x: "; cin >> x; cout << "Please enter y: "; cin >> y; if(x == 0) { if (y > 0) cout << 0 << endl; else cout << "x^y is not defined" <<endl; } else { cout << improvedPow(x,y)...