my problem is that i have declared aprototype with returning value as float
then inside the function i sayed the if a condetion satisfy .read som data and then return it
else compleat the loop
at the end of the function i must return avalue but i dont know what to return
this is part of the code :
float FindProduct(string code)
{
//declaring local variabels
string codes;
float uniteprice;
ifstream storeF;
//open storfile and cheaking wether it opens or no
storeF.open("StoreFile");
if (storeF.fail())
{
cout <<"cannot open store file or it dose not exist"<<endl;
return 1;
}
//reading the first code in store file
storeF>>codes;
for(int x=1;x<=13;x++)
{
if (code == codes)
{
//read price of that code
storeF>>uniteprice;
storeF.close();
return (uniteprice);
}
else
//read the next code
storeF >>uniteprice>>codes;
}//end of for loop
return ; }//end of the function
is there any one here can guide me i dont know whaht to do>.<
The code on line 30 of your function will be executed only in case that the opened file doesn't contain the code you're looking for (at least on its first 13 lines - according to your condition x<=13).
This state is obviously an error (similar to the one you test on line 9). Thus you can simply return 1; what (if I'm not mistaken) was your intention for indicating errors.
in the task that i want to solve they want us to print abill for customers we know what are the code and how many quntity did they bought so the we will serch for the code in some file and then read the price as iv showed up
i can simply use built in function find() but i dont know how to use it kind of new.......
There are three return statements in your function (three branches). One of the branches is valid (according to your criteria) returning uniteprice, the other two are invalid. These two should return some value indicating an error (often is used -1).
You can then test the value e.g.
1 2
float Result = FindProduct(SomeString);
if (Result==-1) { /* appropriate action */ }