I have been working on a program designed to read data from several lines of a text file. I have had no problem with the first line but I am not sure how to move onto line 2, 3, etc.
The contents and length of the file are not set, but the contents could be something like this:
1.0 1.0 C
1.0 1.0 V
1.0 1.0 S
1.0 1.0 D
1010.0 250.0 C
999
This is my program (so far);
#include <fstream>
#include <iostream>
#include <string>
#include <iomanip>
#include <math.h>
using namespace std;
int main()
{
double radius;
double height;
char letter[1];
char Exercise4[80] = "Exercise4.txt";
ifstream infile;
infile.open (Exercise4);
infile >> radius >> height >> letter;
while (radius != 999) {
cout << endl << endl;
double Pi;
Pi = 3.141592;
cout << setprecision(2) << fixed;
//math & calculations
double Circ;
Circ = radius*2*Pi;
double Surf;
Surf = (2*Pi*radius*radius)+(2*Pi*radius*height);
double Vol;
Vol = Pi*radius*radius*height;
if (strcmp(letter, "C") == 0) {
cout << "Circumfrence: " << Circ << endl;
}
else if (strcmp(letter, "S") == 0) {
cout << "Surface Area: " << Surf << endl;
}
else if (strcmp(letter, "V") == 0) {
cout << "Volume: " << Vol << endl;
}
else {
cout << "Invalid calculation type." << endl;
}
cout << letter;
}
}
Any info on how to move forward by a line would be deeply appreciated.
I am sorry if this question has already been posted (it seems like it would have been), but I have not seen it posted anywhere.
I am relatively new to C++, so I might not understand everything you say if you get too technical.