Basic Question about Passing Values between Functions
Here is a basic program that computes square feet of a house. It ask how many rooms...then ask for the width and length of each room, and then totals square foot from that. I wrote this program myself, and can do it without functions. But I am working on functions, and I cannot get the values passed right. I just don't really understand how to pass values yet I guess:) I want to pass the value of rooms between 2 functions named HOWMANYROOMS and SQUAREFEET. The program just dies after I enter the rooms (it goes back to dos prompt. I am using the Dos Prompt Command from Visual Studio 2010 by the way. Here is the program. I want to keep is as basic as possible for right now:)...there are probably better more efficient ways of programming it, but I want to just keep it very basic to learn the basics.
Thanks for any and all help received. I appreciate it very much.
Code:
#include <stdio.h>
int howmanyrooms(int rooms);
int squarefoot(int totalsquare, int rooms);
int main(void)
{
int totalsquare = 0;
int rooms = 0;
printf("This program computes square footage of a house.\n");
howmanyrooms(rooms);
squarefoot(totalsquare, rooms);
printf("Total Square Foot is %d", totalsquare);
return 0;
}
int howmanyrooms(int rooms)
{
printf("How many rooms are in this house?\n");
scanf("%d", &rooms);
return rooms;
}
int squarefoot(int totalsquare, int rooms)
{
int roomnumber, width, length, roomsquare, i;
roomnumber = 1;
for (i = 0; i < rooms; ++i)
{
printf("What are the width of room %d\n", roomnumber);
scanf("%d", &width);
printf("What is the length of room %d\n", roomnumber);
scanf("%d", &length);
roomsquare = width * length;
totalsquare = totalsquare + roomsquare;
++roomnumber;
}
return totalsquare;
}