When I execute my program, a blank command window pops up - no syntax errors?

closed account (oN3k92yv)
There are no syntax errors in my program, but whenever I run it, nothing is shown in the command window. Why?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/*This program calculates inventory data*/

#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>
#include <sstream>

using namespace std;

int main()
{
	string tool;
	double unitCost;
	double numberOfUnits;
	double totalCost = 0;
	char ch = ' ';
	bool done = false;
	ifstream input;
	int count = 0;




	ifstream inFile;
	ofstream outFile;

	cout << fixed << setprecision(2);

	inFile.open("janeInventory1.txt");

	if (!inFile)
	{
		cout << "Cannot open input file. Program Terminates! " << endl;

		return 1;
	}

	outFile.open("janeInventory1.out");

	for (int i = 0; i < 6; i++)

	{
		cin >> tool >> numberOfUnits >> unitCost;
		cout << tool << " " << numberOfUnits << " " << unitCost << endl;
	}

	return 0;


	outFile << fixed << showpoint << setprecision(2);

	inFile >> tool >> numberOfUnits >> unitCost;

	while (inFile)
	{
		totalCost = numberOfUnits * unitCost;

	}

	cout << "**************************************************************************" << endl;
	cout << "Inventory for Jane Doe National Hardware " << endl;
	cout << "**************************************************************************" << endl;
	cout << endl;
	cout << "ITEM         NUMBER OF UNITS              UNIT COST ($)                  TOTAL VALUE " << endl;
	cout << "***************************************************************************" << endl;

	ch = ' ';

	while ((ch = input.peek() != EOF))
		string tool = "";
	double units = 0.0;
	double cost = 0.0;

	input >> tool >> units >> cost;

	cout << left << setw(9) << tool;
	cout << left << setw(15) << units;
	cout << left << setw(25) << cost;
	cout << left << setw(20) << numberOfUnits * unitCost;









}


You have an infinite loop beginning on line 55.
closed account (oN3k92yv)
I removed the return 0; on line 48, and how do I break out the inifinite loop? return (0);?
Change while (inFile) to incorporate a condition.or maybe use a break... again, you'd want it to have a condition to make a decision from.

In the compound statement governed by a loop condition, you should do something that will eventually make the condition evaluate to false. In that particular loop, for instance, you might actually read from the file instead of repeating the same calculation over and over.
I would guess that you want this:
1
2
3
4
5
	while (inFile >> tool >> numberOfUnits >> unitCost)
	{
		totalCost = numberOfUnits * unitCost;

	}
Topic archived. No new replies allowed.