Abnormally terminating program when using if-else loop

Hey all,

A complete novice here looking for assistance w/ coding here. It's simple..just employing the use of two functions. One function prompts the user for information while the 2nd displays information regarding an order.

The program requires me to enter in a number of ordered items. If that number exceeds the stock (which I assigned as a fixed number) then the program must store the additional wires in backstock or program. I figured that the only way to accomplish this would be using an if-else loop.

The program compiles fine! But after submitting a number which exceeds the stock the if-else loop executes but the window closes randomly! How do I fix this? Here's what I've got thus far. Please keep in mind that it is a first draft and I've still got some more editing to do.


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
//This program intends to employ the use of functions 

#include <iostream>
using namespace std; 


int calcVal(int num1, int num2, double num3) 

{
 int per; 
 int backstock; 
 double final;
 double ship; 
 per = 100.00; 
 ship = 10.00; 
 final = num1 * per * ship + num3;
 backstock = 1000000;
 
 
 
 
    
	cout << "\nYou ordered " << num1 << " spools.\n";
    cout << "\nYou currently have " << num2 << " spools in stock.\n";
         if (num2 >= 1000000)
            {
                  cout << "Quantity entered exceeds maximum amount of stock.\n";
                  cout << num3 - backstock << "stocks of copper wire have been added to your backorder."; 
                   
                  
                  }  
          else
              
    cout << "\nYou entered in " << num3 << " additional shipping charges.\n";
    cout << "\nYour total amount comes out to $ " << final << ".\n"; 
    
    return final; 
    
}


int main ()

{

	int val1, val2; 
	double val3; 
	char y;

		cout << "Number of spools ordered? ";
		cin >> val1;  
        cout << "\nNumber of current spools in stock? ";
        cin >> val2; 
        cout << "\nThe standard shipping charges are $10\n"; 
        
        cout << "\nAdditional charges? "; 
        cin >> val3;
		
		calcVal(val1, val2, val3);
		cout << "\nPlease Press the RETURN key to terminate this program.";
		cin >> y;  
        cin.get(y);
		
		return 0;
		
		

}
Topic archived. No new replies allowed.