I was able to correctly write the program using functions, but afterwards started playing around with it to see if I could write it another way.
Could someone explain to me why the following returns errors? Xcode keeps returning “control reaches end of non void function”, but I’m not familiar with that. My assumption was that secondInt would supply the variable 5 to the square function, allowing it to compute the square and then print all of it.
#include <stdio.h>
int square (int root)
{
int newstNum = root;
int newNumber = root * root;
printf("\"%d\" squared is \"%d\".\n", newstNum, newNumber);
}
int main(int argc, const char * argv[])
{
int firstInt = 5;
int secondInt = square (firstInt);
return 0;
}