c++ code problem

I have a problem with my output. When I input no values and click run, this is what my output says:

Program generated too much output.
Output restricted to 50000 characters.

Check program for any unterminated loops generating output.


**How do I fix this so I don't get this message? If you can fix this, thanks!***
**Below is my coding:

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
#include <iostream>
#include <iomanip> // std::setprecision
using namespace std;
// Function Declarations
void readInputData(int& spoolsOrdered, int& spoolsInStock, double& shippingCharges);
void display(int spoolsOrdered, int spoolsInStock, double shippingCharges);
int main()
{
	// Declaring variables
	int spoolsOrdered, spoolsInStock;
	double shippingCharges;
	// Calling the functions
	readInputData(spoolsOrdered, spoolsInStock, shippingCharges);
	display(spoolsOrdered, spoolsInStock, shippingCharges);
	return 0;
}
// This function will read the inputs entered by the user
void readInputData(int& spoolsOrdered, int& spoolsInStock, double& shippingCharges)
{
	/* This while loop continues to execute
	* until the user enters a valid number
	*/
	while (true)
	{
		cout << "Spools to be ordered";
		cin >> spoolsOrdered;
		if (spoolsOrdered < 1)
		{
			cout << "\nSpools order must be 1 or more" << endl;
			continue;
		}
		else
			break;
	}
	/* This while loop continues to execute
	* until the user enters a valid number
	*/
	while (true)
	{
		cout << "\nSpools in stock";
		cin >> spoolsInStock;
		if (spoolsInStock < 1)
		{
			cout << "\nSpools in stock must be 0 or more" << endl;
			continue;
		}
		else
			break;
	}

	char ch;
	cout << "\nSpecial shipping and handling (y or n)";
	cin >> ch;
	if (ch == 'y')
	{
		/* This while loop continues to execute
		* until the user enters a valid number
		*/
		while (true)
		{
			cout << "\nShipping and handling amount";
			cin >> shippingCharges;
			if (shippingCharges < 0)
			{
				cout << "\nThe spool shipping and handling charge must be 0.0 or more" << endl;
				continue;
			}
			else
				break;
		}
	}
	else
	{
		shippingCharges = 11.88;
	}
}
// This function will display the output
void display(int spoolsOrdered, int spoolsInStock, double shippingCharges)
{
	// Setting the precision to two decimal places
	std::cout << std::setprecision(2) << std::fixed;
	cout << "\nSpools ready to ship: " << spoolsInStock << endl;
	cout << "Spools on back-order: " << spoolsOrdered - spoolsInStock << endl;
	double subtotal = spoolsInStock * 100;
	cout << "Subtotal ready to ship: $" << setw(10) << subtotal << endl;
	cout << "Shipping and handling:  $" << setw(10) << spoolsInStock * shippingCharges << endl;
	double total = (spoolsInStock * 100) + (spoolsInStock * shippingCharges);
	cout << "Total shipping charges: $" << setw(10) << total << endl;
}
Last edited on
Hello bal160730,

You need to be more specific about your problem.

When I input no values and click run

What does this mean because I am not sue how to do this.

When I ran the program it ran fine.

I did notice one problem on line 42. If you enter zero for in stock you will always get an error message.

The "display" function is not right. If you order 10 and have 20 in stock it says -10 on back-order.

Line 84 would be better written as double subtotal = spoolsInStock * 100.0;

I would also use the same 100.0 in line 87 just to be safe.

When you use a floating point number with a variable defined as an int it will promote the int to either a float or double for the calculation.
Hope that helps,

Andy

P.S. Your program would benefit from the use of several blank lines to break up the code.
Last edited on
Topic archived. No new replies allowed.