Order Status

The DEV C++ tends to stop working when it get to void displayOrder. I'm wondering what I did wrong? I also placed one comment in the code explaining what I am trying to do. It may be the cause behind it or not.

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
#include <iostream>
#include <iomanip>
          
using namespace std;

double getSpools(double, double, double);
void displayOrder(double, double, double);

int main ()
{

double ordered, stock, charges;

cout << fixed << showpoint << setprecision(2);    
    
getSpools(ordered, stock, charges);
displayOrder(ordered, stock, charges);

system ("pause"); 
return 0;
}
double getSpools(double ordered, double stock, double charges)
{
     char   specialChargeYN;
     
     cout << "The number of spools ordered: ";
     cin >> ordered;
     
     while (ordered < 1)
           {
                    cout << "\n\nInvalid Input.\n\n\nEnter a number higher than 1: ";
                    cin >> ordered;
           }
           
     cout << "\n\nThe number of spools in stock: ";
     cin >> stock;
     
     while (stock < 0)
           {
                    cout << "\n\nInvalid Input.\n\n\nEnter a number higher than 0: ";
                    cin >> stock;
           }
           
     cout << "\n\nAny special shipping and handling (Y/N)? ";
     cin >> specialChargeYN;
     
     if ((specialChargeYN == 'Y') || (specialChargeYN == 'y'))
        {
                    cout << "\n\nWhat are the special charges per spool? $";
                    cin >> charges;
                    
                    while (charges <= 10) 
                          {
                                  cout << "\n\nInvalid Input.\n\n\nEnter a number higher than 10: ";
                                  cin >> charges;
                          }
        }
     else if ((specialChargeYN == 'N') || (specialChargeYN == 'n'))
        {
                    charges = 10.00;
        }
}
void displayOrder(double ordered, double stock, double charges)
{
     double backOrder = 0, ship, perSpool, totalCost, specialCharges;
     
     cout << "\n\nThe number of spools ready to ship from stock: " << ordered;
     
     if (ordered > stock)
        {
                 //I'm trying to get the negative result, then turn it to positive. 
                 backOrder = stock - ordered * (1-2);
                 
                 cout << "\n\nThe number of ordered spools on back order: " << backOrder;
        }
        
        ship = ordered - backOrder;
        
        perSpool = ship * 100.00;
        
     cout << "\n\nThe total selling price of the portion ready to ship $" << perSpool;
     
        specialCharges = ship * charges;
     
     cout << "\n\nThe total shipping and handling charges on the portion ready to ship $" << specialCharges;
     
        totalCost = perSpool + specialCharges;
        
     cout << "\n\nThe total of the order ready to ship $" << totalCost;
     
     cout << "\n\n\n";   
}
Last edited on
How exactly does it stop working?

It doesn't seem like it should crash, so what do you mean stop working?

-Blueberry
@Xesna

1
2
//I'm trying to get the negative result, then turn it to positive. 
                 backOrder = stock - ordered * (1-2);


To set your number to a positive, you could use
backOrder = abs(stock - ordered);
I think it's more of the DEV C++ that isn't working properly, but anyway; is there any problem with my coding? No syntax or logical errors? I can't run it while "Windows is looking for a solution."
closed account (S6k9GNh0)
How do you know its not working?
Also, if you're using the compiler that comes with Dev-C++ from 2005, then it might be the compiler. Otherwise, never doubt the compiler unless it's a real edge case.
I'm running the code every time and the moment it encounters:

The number of spools ready to ship from stock:


It gives me a message that the Order Status has stopped working. Windows is looking for a Solution.

If it's the compiler, can anyone redirect me to acquire a new one. However, if it's not the compiler, then there's a bug in the coding that it can't seem to find.

Previous EDIT: No. It isn't the compiler. I ran my other programming challenges and they worked fine. Thus, ruling out that possibility and leaving with the code.

EDIT: I found the error, it required the use of references and in case anyone who's learning C++ in the future:

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
94
95
#include <iostream>
#include <iomanip>
#include <cmath>
          
using namespace std;

double getSpools(double &ordered, double &stock, double &charges);
void displayOrder(double, double, double);

int main ()
{

double charges, ordered, stock;    
    
getSpools(ordered, stock, charges);

displayOrder(ordered, stock, charges);

system ("pause"); 
return 0;
}
double getSpools(double &ordered, double &stock, double &charges)
{
     char   specialChargeYN;
     
     cout << "The number of spools ordered: ";
     cin >> ordered;
     
     while (ordered < 1)
           {
                    cout << "\n\nInvalid Input.\n\n\nEnter a number higher than 1: ";
                    cin >> ordered;
           }
           
     cout << "\n\nThe number of spools in stock: ";
     cin >> stock;
     
     while (stock < 0)
           {
                    cout << "\n\nInvalid Input.\n\n\nEnter a number higher than 0: ";
                    cin >> stock;
           }
           
     cout << "\n\nAny special shipping and handling (Y/N)? ";
     cin >> specialChargeYN;
     
     if ((specialChargeYN == 'Y') || (specialChargeYN == 'y'))
        {
                    cout << "\n\nWhat are the special charges per spool? $";
                    cin >> charges;
                    
                    while (charges <= 10) 
                          {
                                  cout << "\n\nInvalid Input.\n\n\nEnter a number higher than 10: ";
                                  cin >> charges;
                                  
                                  charges;
                          }
        }
     else
        {
                    charges = 10.00;
        }
}
void displayOrder(double ordered, double stock, double charges)
{
     double backOrder = 0, shipping, perSpool, totalCost, specialCharges;
     
     cout << "\n\nThe number of spools ready to ship from stock: " << ordered;
     
     if (ordered > stock)
        { 
                 backOrder = abs(stock - ordered);
                 
                 cout << "\n\nThe number of ordered spools on back order: " << backOrder;
        }
        
        cout << fixed << showpoint << setprecision(2);
        
        shipping = ordered - backOrder;
        
        perSpool = shipping * 100.00;
        
     cout << "\n\nThe total selling price of the portion ready to ship $" << perSpool;
     
        specialCharges = shipping * charges;
     
     cout << "\n\nThe total shipping and handling charges on the portion ready to ship $" << specialCharges;
     
        totalCost = perSpool + specialCharges;
        
     cout << "\n\nThe total of the order ready to ship $" << totalCost;
     
     cout << "\n\n\n";   
}
Last edited on
Topic archived. No new replies allowed.