+ 2

c++ closing this infinite loop...

Hello! I have been trying to close this infinite loop but have been unsuccessful! I can't seem to figure out the condition in this program that is always true. Someone please help me!! And thank you! //DATE: ///The following program takes input from an investment portfolio and displays ///the content to the output device (monitor/outfile). It also calculates the ///total invested, Possible annual holdings for maximum loss and gain and whether ///the portfolio is a sound investment or not. Outputting the information to the output ///device as well. #include <iostream> #include <iomanip> #include <fstream> #include <math.h> using namespace std; int main() { cout << "Student Name: Sean O'Neil" << endl;//Programmer: cout << "CS150 SP18" << endl;//CS150 SP18 cout << "TA: Rozhin" << endl;//TA: cout << "3/19/18" << endl;///PART A Declare and Initialize____________________________________________________________________________ ///1. Declare and INITAILIZE the variables string symbol; double Invested_amount = 0; float investedAmount; float maximumReturn; float maximumLoss; float totalInvested; float maxReturnOverall; float maxLossOverall; double is_sound = 0; string choice = "1"; string outFile_name; string inFile_name; ///2.Declare the input file ifstream inFile; ///3.Declare the output file ofstream outFile; ///4.OUTER WHILE LOOP GOES HERE while (choice == "1") { ///5. Set output fixed, showpoint, setprecision of two for all decimals cout << fixed << showpoint << setprecision(2); ///6. Prompt user for the input file(Ex. folio1.txt): cout << "Please enter the input file name and please include the .txt extension (EX: folio1.txt) "; cin >> inFile_name; ///a. Open the input file using the users input, remember to convert string to a c string (ex. filename.c_str()) inFile_name.c_str(); ///b. Include error handling: if file cannot be fo

19th Mar 2018, 9:29 PM
Arbiter
11 ответов
+ 3
Im sorry I cant help with this one
19th Mar 2018, 9:32 PM
TrueJu
TrueJu - avatar
+ 3
@Arbiter, what @Jonathan Carver mean was for you to remove your comments/posts on this thread, not to remove comments on the code, please follow his suggestion. Also put back the comments in the code, and mind code indentation, it's really difficult reading it when indentation is not well arranged. So far I noticed you may experience compilation error due to invalid character ']' I see in the code, I'm not sure what they are there for, but you might wanna look at it to begin with. I need you to explain in brief (write in code header) the following: - What this code is for (purpose). - What input(s) was required from user. - What the input & output file are for. And data format of input & output file. - Are you using data from input file to process the information. I don't know if I can help you much, but I will try.
20th Mar 2018, 2:22 PM
Ipang
+ 2
Here is more of it! ///a. Open the input file using the users input, remember to convert string to a c string (ex. filename.c_str()) inFile_name.c_str(); ///b. Include error handling: if file cannot be found -> exit program if (inFile == 0) { cout << "ERROR File not found." << endl; return 0; } else { ///6. Prompt user for the output file ///a. Use a DO-WHILE to avoid overwriting the input file do { cout << "Please enter the output file name but make sure to add the .txt extension and to not make it the same as the input file name, for that can cause overwriting." << endl; cin >> outFile_name; } while (outFile_name == inFile_name); ///b. Open the output file using the users input, remember to convert to a c string (ex. filename.c-str()) outFile.open(outFile_name.c_str()); ///PART B Input and computations____________________________________________________________________________ ///7. Output the table heading to the monitor and output file here (EX. SYMBOL CURRENT PRICE(USD) INVESTED AMOUNT(USD) MAX Return(%) Max Loss(%)) ///Remember to use the iomanipulator class to format the output cout << setfill(' ') << left << setw(15) << "Symbol" << setw(25) << "Current Price (USD)" <<setw(25) << "Invested Amount (USD)" << setw(20) << "Max Return (%)" << setw(20) << "Max Loss (%)" <<endl; ///8. Utilize a WHILE loop to open the input file and extract the information sequentially until end of file. while(!inFile.eof()) { ///a. Get (read) file input cout << inFile; ///b. Compute Max_return, Max_loss, Total_invested using a summation that continually compounds on the previous input totalInvested += Invested_amount; //maximumReturn = ///c. Output all information for each stock/asset currently in the loop (EX. QCV 30 300 100 100) cout << inFile << symbol << Invested_amount << maximumReturn << maximumLoss; }///End of whil
19th Mar 2018, 9:30 PM
Arbiter
+ 2
And the last chunk! ///9. Compute the aggregate values utilizing Max Return, Max Loss, and Total invested totalInvested += investedAmount; maxReturnOverall = maximumReturn / totalInvested; maxLossOverall = maximumLoss / totalInvested; ///10. Check whether the investment portfolio is sound using the equation IsSound = 0.40 * Investment after Max Return percent - 0.60 * Investment after Max Loss percent is_sound = 0.4 * investedAmount + ((maxReturnOverall - .6) * (maxLossOverall)); ///Part C Output_____________________________________________________________________________________ cout << endl; outFile << endl; ///11. Output results to the monitor, utilize the output manipulators cout << left << setw(10) << "Annual Analysis: " << endl; ///12. Output results to the file, utilize the output manipulators cout << outFile; ///13. Check if the portfolio is a good investment, if IsSound > 1 is_sound = .4 * maxReturnOverall - .6 * maxLossOverall; ///a. If it is then output that the investment is sound to both monitor/output file, if (is_sound > 1) { cout << "This portfolio is a sound investment." << endl; } else { cout << "This portfolio is NOT a sound investment." << endl; } ///otherwise output that the investment is not sound. ///14.Close the input and output files. cout << "Would you like to process another file? Enter 1 if yes, if not, enter any other key." << endl; cin >> choice;///15. Prompt user for continuation of program. 1 = Continue, Any other character = Exit. } }///END OF OUTER WHILE LOOP return 0; }
19th Mar 2018, 9:31 PM
Arbiter
+ 2
You know what would be a really good idea? How about you delete every comment you've posted on this, and put the entire program into the Code Playground, and then attach it here, instead of posting 5 different code snippets to look through confusingly.
19th Mar 2018, 10:02 PM
Dread
Dread - avatar
+ 1
You didn't remove the comments on this post because they are still here... I want you to put this all into CP, and save it and LINK it here.
20th Mar 2018, 11:05 AM
Dread
Dread - avatar
0
#include <iostream> #include <iomanip> #include <fstream> #include <math.h> using namespace std; int main() { cout << "Student Name: Sean O'Neil" << endl; cout << "CS150 SP18" << endl; cout << "TA: Rozhin" << endl; cout << "3/19/18" << endl; string symbol; double Invested_amount = 0; float currentPrice; float investedAmount; float maximumReturn; float maximumLoss; float totalInvested; float maxReturnOverall; float maxLossOverall; double is_sound = 0; string choice = "1"; string outFile_name; string inFile_name; ifstream inFile; ofstream outFile; while (choice == "1") { cout << fixed << showpoint << setprecision(2); cout << "Please enter the input file name and please include the .txt extension (EX: folio1.txt) "; cin >> inFile_name; inFile_name.c_str(); ] if (inFile == 0) { cout << "ERROR File not found." << endl; return 0; } else { do { cout << "Please enter the output file name but make sure to add the .txt extension and to not make it the same as the input file name, for that can cause overwriting." << endl; cin >> outFile_name; } while (outFile_name == inFile_name); outFile.open(outFile_name.c_str()); cout << setfill(' ') << left << setw(15) << "Symbol" << setw(25) << "Current Price (USD)" <<setw(25) << "Invested Amount (USD)" << setw(20) << "Max Return (%)" << setw(20) << "Max Loss (%)" <<endl; outFile << setfill(' ') << left << setw(15) << symbol << setw(25) << currentPrice <<setw(25) << Invested_amount << setw(20) << maximumReturn << setw(20) << maximumLoss <<endl; while(!inFile.eof()) { cin >> symbol >> currentPrice >> Invested_amount >> maximumReturn >> maximumLoss; totalInvested += Invested_amount; ] } cout << symbol; totalInvested += investedAmount;
19th Mar 2018, 11:05 PM
Arbiter
0
] } cout << symbol; totalInvested += investedAmount; maxReturnOverall = maximumReturn / totalInvested; maxLossOverall = maximumLoss / totalInvested; is_sound = 0.4 * investedAmount + ((maxReturnOverall - .6) * (maxLossOverall)); cout << left << setw(10) << "Annual Analysis: " << endl; cout << "Total Invested (USD): " << totalInvested << endl; cout << "Maximum Return (USD): " << maxReturnOverall << endl; cout << "Maximum Loss (USD): " << maxLossOverall << endl; is_sound = .4 * maxReturnOverall - .6 * maxLossOverall; if (is_sound > 1) { cout << "This portfolio is a sound investment." << endl; } else { cout << "This portfolio is NOT a sound investment." << endl; } cout << outFile; cout << "Would you like to process another file? Enter 1 if yes, if not, enter any other key." << endl; cin >> choice; } } return 0; }
19th Mar 2018, 11:07 PM
Arbiter
0
If you keep this up, I feel like it can be classified as spam.
19th Mar 2018, 11:07 PM
Dread
Dread - avatar
0
Now the new problem is that no data is outputted onto the console! And here is the link!! https://code.sololearn.com/chbw5dSCL6Oh/#cpp
19th Mar 2018, 11:07 PM
Arbiter
0
I removed the comments and ran it through the code playground like how you said!! I just need help please.
19th Mar 2018, 11:08 PM
Arbiter