fstream problem

Hello,
i want to create a simple program which:
1.takes from a file some datas:(kbts/sec + time wanted to complete)for a download
2.finds the bandwidth
3.shows in an other file how much time is needed to complete download

ex. 2(the amount of files)
3 57
2 22
The program must:
1.find bandwidth(3+2=5).
2.find the total size(2*22=44),44+(3*57=171),44+171=215kbts
3.find the total time(215/5=43sec)
4.show the result

Now my problem:
i have to use fstream in order to take input and produce output from and to files

but i can have from 1-100 downloads

the error is:

#include<iostream>
#include<fstream>
using namespace std;

int main()
{
ifstream in("downloads.in");
ofstream out("downloads.out");

int n,time,size,kbts,t_size,t_kbts,total,counter;
in>>n;
int x[n],p[n],t[n];
time=0;
kbts=0;
for(counter=0;counter<n;counter++)
in>>x[i]>>p[i]; -->there it says i cant do that
t[i]=p[i]*x[i];
for(counter=0;counter<n;counter++)
{t_size+=t[i];
t_kbts+=x[i];}
total=t_size/t_kbts;
out<<total;
in close();
out close();
return 0;
}


so what????? x=kbts/sec p=time needed t=size

PLEASE TRY IT BY YOURSELF AND TELL ME HOW TO FIX THIS
THANKS A LOT
Last edited on
you can have in download.in a line where is 0,0;this are stop the program..

1
2
while(n!=0)
//do that..{you program^} 


and..i=?..s=?..please tell me this var..
i=i think when you have a table for ex

sample[10]

and you want to add the first var in your table you use smt for ex

sample[i]-->in a for.

so when for is rereaded sample[i] is sample[i1]

a program for example.

#include<iostream>
using namespace std;

int main()
{
int n=5;
int i, x[n],sum;
sum=0;
for(i=0;i<n;i++)
{
cin >>x[i];
sum=sum+x[i];
}
for(i=0;i<n;i++)
{
cout<<"\n";
cout << x[i]<<"\n";
}
cout<<sum;
system("pause");
return 0;
}
can someone show me the code pls. I mean smt that works. I need this program... :)
Topic archived. No new replies allowed.