calling a function

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;
}
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.
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
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
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
You have a couple of choices:

1) If you're using C++11, you can use to_string():
http://www.cplusplus.com/reference/string/to_string/

 
  shipping = to_string(10.00);


2) Or you can use std::stringstream. stringstream gives you all the formatting power of an ostream but stores the result in a string.
http://www.cplusplus.com/reference/sstream/stringstream/

1
2
3
  stringstream ss;
  ss /* << any io manipulators you want */ << 10.00;
  shipping = ss.str();  // Copy the formatted string 

Last edited on
am i supposed to define the string in the main function or in the second function
Topic archived. No new replies allowed.