C++ while loop problem?

include<iostream>

#include<string>

#include<fstream>

#include<iomanip>

using namespace std;

int main(){

ifstream fin;

fin.open("monthlyPrecipitation1.txt");

ofstream fout("annualPrecipitation.txt");

string cityName;

double num1,num2,num3,num4,num5,num6,num7,num8,num9,num10,num11,num12;

int height;

double annualPrecipitation;

fout<<"Annual Precipitation"<<endl<<endl;

getline(fin,cityName,'\t');

while (fin>>cityName)

{

fin>>height>>num1>>num2>>num3>>num4>>num5>>num6>>num7>>num8>>num9>>num10>>num11>>num12;

annualPrecipitation=num1+num2+num3+num4+num5+num6+num7+num8+num9+num10+num11+num12;

fout<<cityName<<endl;

fout<<height<<endl<<num1<<endl<<num2<<endl<<num3<<endl<<num4<<endl<<num5<<endl<<num6<<endl<<num7<<endl<<num8<<endl<<num9<<endl<<num10<<endl<<num11<<endl<<num12<<endl;

fout<<annualPrecipitation;

}

fin.close();

}

The loop is to get information from a text document

The rel="nofollow">http://i52.tinypic.com/34ipdv6.png

Yes I realize that it is outputting all the numbers to the screen, that is just to check to make sure the program is gathering the correct inputs.

Lastly: Here is the data it collects for the first 3 rows

AGUA CANYON 8900 2.4 3.1 2.7 1.9 1.5 0.9 1.9 2.7 2.3 2.1 2.2 2.4

BEAVER DAMS 8000 2.9 2.8 3.4 3.4 2.2 0.9 1.1 1.7 1.9 2.4 2.7 2.7

BEAVER DIVIDE 8280 3.3 3.1 3.3 3.3 2.6 1.5 1.4 1.8 1.8 2.2 2.9 3.3

Please enter comments
Please enter your name.
Please enter the correct email address.
You must agree before submitting.

Answers & Comments


Helpful Social

Copyright © 2024 Q2A.ES - All rights reserved.