我不断收到错误消息,说明''rate'在此函数中未初始化“。未初始化的变量故障C++
任何人都可以看到为什么?我查看了我的代码,并将其正确地传递给我的其他函数,并且错误源于此函数。有任何想法吗?
double compute_rate(int userAge_array[], char sportType_array[], int index)
{
double rate;
if (sportType_array[index] == 'f') {
if (userAge_array[index] < 25) {
rate = 68.95;
}
else if (userAge_array[index] > 25) {
rate = 55.95;
}
}
if (sportType_array[index] == 'g') {
if (userAge_array[index] < 25) {
rate = 73.95;
}
else if (userAge_array[index] > 25) {
rate = 65.95;
}
}
if (sportType_array[index] == 'h') {
if (userAge_array[index] < 25) {
rate = 99.95;
}
else if (userAge_array[index] > 25) {
rate = 92.95;
}
}
return rate;
}
当你达到“退货率”时会发生什么?没有任何'rate ='行? –
假设'sportsType_array [index] =='a'' – rwols
如果sportType_array [index]是f,g,h,比如说'z'以外的东西,那么比率是多少? –