Okay, I'm trying to figure out what's going wrong with this program. I thought I figured out the problem, but no it is not doing it. I've wracked my brain for this for over a week and I can't figure out what's making it stupid. I'll also include the header file. Also here are the errors that come up in the complier:
1 2 3
Warning 1 warning C4800: 'StudentRecord *' : forcing value to bool'true' or 'false' (performance warning) c:\users\christina\documents\visual studio 2013\projects\array\arrayrecord.cpp 47 1 Array
Error 2 error C2562: 'ArrayRecord::Modify' : 'void' function returning a value c:\users\christina\documents\visual studio 2013\projects\array\arrayrecord.cpp 129 1 Array
3 IntelliSense: return value type does not match the function type c:\Users\Christina\Documents\Visual Studio 2013\Projects\Array\ArrayRecord.cpp 129 41 Array
Error 2 error C2562: 'ArrayRecord::Modify' : 'void' function returning a value c:\users\christina\documents\visual studio 2013\projects\array\arrayrecord.cpp 129 1 Array
The code tries to return a value from a function defined to return nothing (void).
1 2 3 4 5 6 7 8 9 10 11
void ArrayRecord::Modify(int id,char*,char*,float,char*)
{
int location = 0;
int item;
while (location < length)
{
if (list[location].id == item) return &list[location];
else location++;
}
/*Do a search if it's found then modify the selection but if it's not found then insert a new info*/
}
It doesn't sound like you need to return a value unless you want to confirm that an update took place (bool - true/false) or you need to know what location was updated back in the calling function?
Also - item is uninitialized - how do you know if there is a match here? if (list[location].id == item)
Okay a few things. For the parameters of Modify, what I will need to change is this, right? if (list[location].id == item) return &list[location];
I would also like modify to show what record was updated. But I'm not sure how to start that.
Also, item being uninitialized, will it need to be set to 0 or 1? I'm not getting exactly what you mean by the it being matched.
If modify is going to return the location, the return type can't be void - it needs to be the type of whatever value you want to return.
For the parameters of modify - you need to replace the name below with whatever that variable is going to be called in the function.
1 2 3 4 5 6 7 8 9 10 11 12
void ArrayRecord::Modify(int id,char* name,char* name,floatname,char* name)
{
int location = 0;
int item; //item has no valid value
while (location < length)
{
//item has no valid value - how do you know it's equal to the id value in the current location?
if (list[location].id == item) return &list[location];
else location++;
}
/*Do a search if it's found then modify the selection but if it's not found then insert a new info*/
}