Nov 14, 2015 at 5:34am UTC
i am having issues with a question which requires the calling of a function but i don't see what I've done wrong in my code.
#include <iostream>
using namespace std;
void getspools(int&, int&, double&);
void numspools(int&, double&);
int spoolsordered;
int spoolsinstock;
double special;
int main()
{
void getspools();
void numspools();
return 0;
}
void getspools(int spoolsordered, int spoolsinstock, double special)
{
cout << "enter the number of spools ordered :" << spoolsordered << endl;
cout << "enter the spools in-stock: " << spoolsinstock << endl;
cout << "is there any special shipping charge? yes or no? " << special << endl;
if(special = "yes")
{
cout << "enter special shipping charge: $" << endl;
cin >> special;
}
else if (special = "no")
{
special = 10.00;
cin >> special;
}
}
void numspools(int &backorder, double &spoolship, double &salesprice, double &shipping, double &totalorder)
{
cout << "enter the number of spools ready to ship from current stock: " << endl;
cin >> spoolship;
if(spoolsordered >= spoolsinstock)
{
spoolsordered = spoolship;
backorder = spoolsinstock - spoolsordered;
cout << "number of spools in backorder: " << backorder << endl;;
}
else
{
spoolship = spoolsinstock;
backorder= spoolsordered - spoolsinstock;
}
salesprice = spoolship * 100;
shipping = spoolship * special;
totalorder = (salesprice * shipping) + special;
cout << "total sales price of portion ready to ship: $" << salesprice << endl;
cout << "total shipping and handling cost: $" << shipping << endl;
cout << "total order ready to ship cost: $" << totalorder << endl;
}
Nov 14, 2015 at 6:10am UTC
You made a variable called special which is a double, make it a string because you can't compare a double to a string of characters.
Nov 14, 2015 at 11:03pm UTC
i made it a string but when i compile the output shows nothing.
#include <iostream>
#include <string>
#include<cmath>
using namespace std;
void getspools(int&, int&);
void numspools(int&, double&);
int spoolsordered, spoolsinstock, shipping;
int main()
{
void getspools();
void numspools();
return 0;
}
void getspools(int spoolsordered, int spoolsinstock)
{
cout << "enter the number of spools ordered :" << endl;
cin >> spoolsordered;
cout << "enter the spools in-stock: " << endl;
cin >> spoolsinstock;
string shipping = "shipping";
cout << "is there any special shipping charge? yes or no? " << endl;
cin >> shipping;
if(shipping == "yes")
{
cout << "enter special shipping charge: $" << endl;
cin >> shipping;
}
else
{
shipping = 10.00;
}
}
void numspools(int &backorder, double &spoolship, double &salesprice, double &totalshipping, double &totalorder)
{
cout << "enter the number of spools ready to ship from current stock: " << endl;
cin >> spoolship;
if(spoolsordered >= spoolsinstock)
{
spoolsordered = spoolship;
backorder = spoolsinstock - spoolsordered;
cout << "number of spools in backorder: " << backorder << endl;;
}
else
{
spoolship = spoolsinstock;
backorder= spoolsordered - spoolsinstock;
}
salesprice = spoolship * 100;
totalshipping = spoolship * shipping;
totalorder = (salesprice * shipping) + totalshipping;
cout << "total sales price of portion ready to ship: $" << salesprice << endl;
cout << "total shipping and handling cost: $" << totalshipping << endl;
cout << "total order ready to ship cost: $" << totalorder << endl;
}
Last edited on Nov 14, 2015 at 11:06pm UTC
Nov 14, 2015 at 11:42pm UTC
Line 11-12: These are function prototypes, not function calls. Remove the
void
.
If you're calling these as functions, you need to pass arguments per the function prototypes at line 5-6.
Line 33: You can't assign a double to a string.
Line 43: You're assigning a double to an int. Truncation may occur.
PLEASE USE CODE TAGS (the <> formatting button) when posting code.
http://v2.cplusplus.com/articles/jEywvCM9/
It makes it easier to read your code and it also makes it easier to respond to your post.
Hint: You can edit your previous post, highlight your code and press the <> formatting button.
Last edited on Nov 14, 2015 at 11:44pm UTC
Nov 15, 2015 at 12:53am UTC
i dont know why im not understanding it. but can anyone please explain how to define a string or how i can make "shipping" in the code to string
Last edited on Nov 15, 2015 at 12:55am UTC
Nov 15, 2015 at 1:10am UTC
Last edited on Nov 15, 2015 at 1:10am UTC
Nov 16, 2015 at 7:52pm UTC
am i supposed to define the string in the main function or in the second function