Code not entering if statement block

#include <iostream>
#include <fstream>
#include <sstream>
using namespace std;
#include "Shape.h"
#include "Circle.h"
#include "Rectangle.h"
#include "Square.h"

void Shape::setArea(double area){
this->area = area;
return;
}
double Shape::getArea() const{
return area;
}
void Shape::printArea(){
cout<<area;
return;
}

int main() {
ifstream infile;
infile.open ("shapevalues.csv");
if(!infile.is_open()){
cout << "File could not be opened.\n";
return -1;
}
Circle testCircle;
Rectangle testRectangle;
Square testSquare;
string type;
string tempStr;
double radius;
double length;
double width;
double side;
char getchar;

//while (!infile.eof())
//{
getline(infile, type, ',');
if (type == "circle")
{
infile>>radius;
testCircle.setRadius(radius);
testCircle.calculateArea();
cout<<"Area: "<<testCircle.getArea();
}
else if (type == "rectangle")
{
infile>>length>>width;
testRectangle.setLength(length);
testRectangle.setWidth(width);
testRectangle.calculateArea();
cout<<"Area: "<<testRectangle.getArea();

}
else if (type == "square")
{
infile>>side;
testSquare.setSide(side);
testSquare.calculateArea();
cout<<"Area: "<<testSquare.getArea();
}

getline(infile, type, ',');
cout << type;
if (type == "circle")
{
infile>>radius;
testCircle.setRadius(radius);
testCircle.calculateArea();
cout<<"Area: "<<testCircle.getArea();
}
else if (type == "rectangle")
{
infile>>length>>width;
testRectangle.setLength(length);
testRectangle.setWidth(width);
testRectangle.calculateArea();
cout<<"Area: "<<testRectangle.getArea();

}
else if (type == "square")
{
infile>>side;
testSquare.setSide(side);
testSquare.calculateArea();
cout<<"Area: "<<testSquare.getArea();
}



//}

return 0;
}






I have commented out the while loop to test the code manually and make it easier to read. I have created functions that will calculate the area of the shape based on the type from the infile. Unfortunately, the code is not entering the block and determing the type. It only works the first time.
Input file:

circle,3.5
square,3
rectangle,38,36
circle,23
rectangle,2,13
square,12
square,24
square,1
square,8
square,27
rectangle,22,13
rectangle,22,18
rectangle,14,27
circle,11
circle,18
square,5
watch your variables in a debugger

"circle,3.5\nsquare,3" the input buffer
"3.5\nsquare,3" after the getline()
"\nsquare,3" after reading the radious


also, infile>>length>>width; will choke on the comma.
Topic archived. No new replies allowed.