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.
//This program intends to employ the use of functions
#include <iostream>
usingnamespace 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;
}