I'm working on a program, and as I'm going through the first part of it, I get these errors for line 55:
error: expected primary-expression before 'int'
error: expected primary-expression before 'int'
error: expected primary-expression before 'int'
error: expected primary-expression before 'int'
I thought that when calling a function, you are supposed to use commas to separate the arguments? If so, I don't understand why it's telling me this.
Now, admittedly, there are probably other errors here as well, since the passing of parameters has got me all confused, but I can't move on to those or finish my program until I fix this part first. Any help is greatly appreciated. I have to finish this one by tonight...
//This is a program that calculates the number of boxes of floor
//tile needed to complete x amount of rooms, given the size of
//the tile to be used.
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cmath>
usingnamespace std;
ofstream outfile;
//Variable declarations
int rooms;
int tileSize;
int lengthFeet;
int lengthInches;
int widthFeet;
int widthInches;
//Function prototypes
void GetTiles(int lengthInches, int lengthFeet, int widthInches, int widthFeet);
int main()
{
//Open outfile for answers
outfile.open("answers.out");
if(!outfile) //Check to make sure outfile opens correctly
{
cout << "Error opening output file." << endl; //If it doesn't, display error message
return 0; //and quit
}
cout << "Enter number of rooms: " << endl; //Prompt for number of rooms to tile
cin >> rooms; //Read in number of rooms to tile
outfile << "Number of rooms entered is: " << rooms << endl;
cout << "Enter size of tile in inches: " << endl; //Prompt for size of tile in inches
cin >> tileSize; //Read in size of the tile in inches
outfile << "Size of tile entered (in inches) is: " << tileSize << endl; //Print out size of tile entered
while( rooms > 0) //While room number is greater than 0
{
cout << "Enter length of room (in feet and inches, separated by a space.): " << endl;//Prompt for room length
cin >> lengthFeet >> lengthInches; //Read in room length in feet and inches
outfile << "Length of room entered (in feet and inches) is: " << lengthFeet //Print out entered amounts
<< " " << lengthInches << endl;
cout << "Enter width of room (in feet and inches, separated by a space.): " << endl; //Prompt for room width
cin >> widthFeet >> widthInches; //Read in room width in feet and inches
outfile << "Width of room entered (in feet and inches) is: " << widthFeet //Print out entered amounts
<< " " << widthInches << endl;
GetTiles(int lengthInches, int lengthFeet, int widthInches, int widthFeet); //Call function
rooms--; //Decrement room number
}
return 0; //Quit
}
//*********************************************************************************
//GetTiles function
void GetTiles(int lengthInches, int lFeetToConvert, int widthInches, int wFeetToConvert)
{
float numTilesL = 0;
numTilesL = (lFeetToConvert / 12) + lengthInches; //Divide feet by 12 and add Inches to get total inches length
cout << "You will need " << ceil(numTilesL) << " tiles for length." << endl; //Round up answer
float numTilesW = 0;
numTilesW = (wFeetToConvert / 12) + widthInches; //Divide feet by 12 and add Inches to get total inches width
cout << "You will need " << ceil(numTilesW) << " tiles for width." << endl; //Round up answer
float totalTiles = 0;
totalTiles = numTilesL * numTilesW; //Multiply total length by width to get total tiles
cout << "You will need " << totalTiles << "tiles total for this room." << endl;
return;
}
Line 51 should be: GetTiles(lengthInches, lengthFeet, widthInches, widthFeet);
You already told the compiler that these are int's, in the function prototype and the function definition.
So you just pass the variables to the function. (:
Aha! Thanks, Lynx. :) Another question, please...
I found some problems with my math in the GetTiles function, but for some reason, my numTilesL and numTilesW are not being rounded up. Did I do that wrong? Here is the edited program. I'd like to round those up for my program, but if I can't figure it out, I guess I could just add one to the answer, but that seems less than ideal...
Can you see where I went wrong?
//This is a program that calculates the number of boxes of floor
//tile needed to complete x amount of rooms, given the size of
//the tile to be used.
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cmath>
usingnamespace std;
ofstream outfile;
//Variable declarations
int rooms;
int tileSize;
int lengthFeet;
int lengthInches;
int widthFeet;
int widthInches;
//Function prototypes
void GetTiles(int lengthInches, int lengthFeet, int widthInches, int widthFeet);
int main()
{
//Open outfile for answers
outfile.open("answers.out");
if(!outfile) //Check to make sure outfile opens correctly
{
cout << "Error opening output file." << endl; //If it doesn't, display error message
return 0; //and quit
}
cout << "Enter number of rooms: " << endl; //Prompt for number of rooms to tile
cin >> rooms; //Read in number of rooms to tile
outfile << "Number of rooms entered is: " << rooms << endl;
cout << "Enter size of tile in inches: " << endl; //Prompt for size of tile in inches
cin >> tileSize; //Read in size of the tile in inches
outfile << "Size of tile entered (in inches) is: " << tileSize << endl; //Print out size of tile entered
while( rooms > 0) //While room number is greater than 0
{
cout << "Enter length of room (in feet and inches, separated by a space.): " << endl;//Prompt for room length
cin >> lengthFeet >> lengthInches; //Read in room length in feet and inches
outfile << "Length of room entered (in feet and inches) is: " << lengthFeet //Print out entered amounts
<< " " << lengthInches << endl;
cout << "Enter width of room (in feet and inches, separated by a space.): " << endl; //Prompt for room width
cin >> widthFeet >> widthInches; //Read in room width in feet and inches
outfile << "Width of room entered (in feet and inches) is: " << widthFeet //Print out entered amounts
<< " " << widthInches << endl;
GetTiles(lengthInches, lengthFeet, widthInches, widthFeet); //Call function
rooms--; //Decrement room number
}
return 0; //Quit
}
//*********************************************************************************
//GetTiles function
void GetTiles(int lengthInches, int lFeetToConvert, int widthInches, int wFeetToConvert)
{
float numTilesL = 0;
numTilesL = ((lFeetToConvert * 12) + lengthInches) / tileSize; //Multiply feet by 12 and add Inches to get total inches length
numTilesL = ceil(numTilesL);
cout << "You will need " << numTilesL << " tiles for length." << endl; //Round up answer
float numTilesW = 0;
numTilesW = ((wFeetToConvert * 12) + widthInches) / tileSize; //Multiply feet by 12 and add Inches to get total inches width
numTilesW = ceil(numTilesW);
cout << "You will need " << numTilesW << " tiles for width." << endl; //Round up answer
float totalTiles = 0;
totalTiles = numTilesL * numTilesW; //Multiply total length by width to get total tiles
cout << "You will need " << totalTiles << " tiles total for this room." << endl << endl;
return;
}