1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Help please

Discussion in 'C++' started by Giannisl97, Dec 29, 2010.

  1. Giannisl97

    Giannisl97 New Member

    Joined:
    Dec 29, 2010
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    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:

    Code:
    #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];
    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
     

Share This Page