Answer to Question #108899 in C++ for Mossa

Question #108899
Explain what is wrong with the following code fragment and write code to correct it:
int main()
{
PersonType family[20],
newBaby("Anny Dube", 20180912, "2 Sept");
//Assume the array family has been initialised
for (int i = 0; i < 20; i++)
if (family.birthday[5] == newBaby.birthday)
cout << family.name[5] << " share a birthday with "
<<newBaby.name;
return 0;
}
1
Expert's answer
2020-04-10T13:39:05-0400
// Explanations in the comments

int main()
{

PersonType family[20],
      newBaby("Anny Dube", 20180912, "2 Sept");

//Assume the array family has been initialised


for (int i = 0; i < 20; i++)

    if (family[i].birthday == newBaby.birthday) // You need to refer to a specific element 
                                                // in the array with the number "i"
                                                // Change: family.birthday[5] --> family[i].birthday

        cout << family[i].name << " share a birthday with " // You need to access the array
                                                            // element with the number "i"
                                                            // Change: family.name[5] --> family[i].name
        << newBaby.name;

return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS