Click here to Skip to main content
15,890,557 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello everyone, I am new to this world, at school right now and my code looks good, but the console isn't producing the appropriate output that I was looking for. Looking for help in figuring out why and how I can avoid this in the future.

Thanks in advance for all your help.

Brandon

C++
#include <iostream>
#include <fstream>
#include <string>
#include <iomanip>
using namespace std;

int main()
{
	ifstream inFile;
	ofstream outFile;

	inFile.open("inData.txt");
	outFile.open("outData.txt");

	string firstName, lastName, name, department;
	double monthlySalary, monthlyBonus, amountBonus, totalIncome, taxes, taxRate, payCheck, distanceTraveled, travelingTime, averageSpeed, coffeeCost, coffeeSales;

	int cupsSold;

	outFile << fixed << showpoint << setprecision(2);
	inFile >> firstName >> lastName >> department;
	name = firstName + lastName;
	outFile << "Name: " << name << ", Department: " << department << endl;

	inFile >> monthlySalary >> monthlyBonus >> taxes;
	amountBonus = (monthlySalary) * (monthlyBonus / 100);
	totalIncome = monthlySalary + amountBonus;
	taxRate = (totalIncome) * (taxes / 100);
	payCheck = totalIncome - taxRate;
	outFile << "Monthy Gross Salary: $" << monthlySalary << ", Monthly Bonus: " << monthlyBonus << "%" << ", Taxes: " << taxes << "%" << endl;
	outFile << "Paycheck: $" << payCheck << endl;

	inFile >> distanceTraveled >> travelingTime;
	averageSpeed = distanceTraveled / travelingTime;
	outFile << "Distance Traveled: " << distanceTraveled << " miles" << ", Traveling time: " << travelingTime << " hours" << endl;
	outFile << "Average Speed: " << averageSpeed << " miles per hour" << endl;

	inFile >> cupsSold >> coffeeCost;
	coffeeSales = cupsSold * coffeeCost;
	outFile << "Number of Coffee Cups Sold: " << cupsSold << ", Cost: $" << 1.50 << " per cup" << endl;
	outFile << "Sales Amount: $" << coffeeSales << endl;

	inFile.close();
	outFile.close();

	return 0;
}


What I have tried:

I have been going back and redoing everything several times without looking back at what I wrote before, in hopes that I have missed something, but I think I have met my level of expertise on it.

The output should show me:

Name: Giselle Robinson, Department: Accounting
Monthly Gross Salary: $5600.00, Monthly Bonus: 5.00%, Taxes: 30.00%
Paycheck: $4116.00

Distance Traveled: 450.00 miles, Traveling Time: 9.00 hours
Average Speed: 50.00 miles per hour
Number of Coffee Cups Sold: 75, Cost: $1.50 per cup
Sales Amount = $112.50

BUT I only get:


C:\Users\Brandon Ness\source\repos\CS265_BNess_Week2_Assignment\Week 2 Project\Release\Week 2 Project.exe (process 25488) exited with code 0.
To automatically close the console when debugging stops, enable Tools->Options->Debugging->Automatically close the console when debugging stops.
Press any key to close this window . . .
Posted
Updated 21-Nov-18 7:00am
Comments
CPallini 21-Nov-18 13:39pm    
You should post the "InData.txt" file content as well. Use "Improve question" for the purpose.
Member 14062665 21-Nov-18 13:51pm    
The inData.txt and outData.txt weren't even written. SO I think that is my problem. The assignment I was given doesn't even say to write those things. More encryptic than i expected, but both of you have helped tremendously, i know the files aren't in the right place and they aren't written, so i just need to learn how to write them, add them and they should display if everything else looks like it's in good shape.
CPallini 21-Nov-18 16:51pm    
Well, your program should READ (and actually tries to read) "inData.txt". Such a file is the input data of your program and must be provided.

1 solution

You must use the debugger because it is an exception which terminates your program. It is a severe bug in your code.

My tip is that the files arent found because the program runs in a different directory.
 
Share this answer
 
Comments
Member 14062665 21-Nov-18 13:51pm    
Thank you, I am getting the files in the right spots now.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900