2016-03-23 16 views
0

Bir ödev yapmak ve zorlukla mücadele etmek. Sorunumu döngü için 'a daraltmış düşünüyorum. Bunu nasıl düzeltebiliriz? Google'da bir cevap bulamadım veya işte bu bana yardımcı oluyor. Verdiğim bazı veri dosyalarını bir dizi yapmak zorundayım. Ardından sonuçları görüntülemek için bir for döngüsü kullanın. girdidir:
1/8/2016,98.550003,96.959999,70798000
1/11/2016,98.970001,98.529999,49739400
1/12/2016,100.550003,99.959999,49154200
vb
Beklenen çıktı yukarıdaki gibi temiz sayılar olmalıdır.
Gözlemlenen çıktı, çok büyük bir sayı karışıklığıdır.
Döngü kullanarak bir Dosyadan Dizi Verilerinin Görüntülenmesi [C++]

//Variable Declaration 
const int SIZE = 400; 
double stockOpen[SIZE]; 
double stockClose[SIZE]; 
double stkCloseAVG=0; 
double minStkClose; 
double maxStkClose; 
int stockVolume[SIZE]; 
int i = 0; 
string name = "r"; 
string stockDate[SIZE]; 
string stockName; 
string filename; 
ifstream in; 
string stkDate, stkOpen, stkClose, stkVol; 
int actSize; 
cout << "Welcome to " << name << "'s stock majigger thingy!" << endl; 
cout << "Please enter the stock name (aapl; spy)" << endl; 
cin >> stockName; 
filename = stockName + ".table.csv"; 
in.open(filename.c_str()); 
if (!in) 
{ 
    cout << "File Error! Please try again! I BELIEVE IN YOU, LOVE!" << endl; 
    system("pause"); 
    exit(-1); 
} 
while (!(in.eof()) && i < SIZE) 
{ 
    getline(in, stkDate, ','); 
    getline(in, stkOpen, ','); 
    getline(in, stkClose, ','); 
    getline(in, stkVol, '\n'); 
    i++; 
    // Check:cout << stkDate << endl <<endl<< stkOpen<<endl << stkClose<<endl << stkVol; 
    //system("pause"); 
} 
actSize = i; 
//system("clr"); 
for (int i=0; i < actSize; i++) // <- Need help here 
{ 
    cout << "Stock Daily Performance Report -" << stockName << endl; 
    cout << setw(10) << "Date" << setw(7) << "Open" << setw(7) << "Close" << setw(11) << "Volume" << endl; 
    cout << setw(10) << stockDate[i] << fixed << setprecision(2) << setw(7) << stockOpen[i] << setw(7) << stockClose[i] << fixed << setprecision(0) << setw(11) << stockVolume[i] << endl; 
    stkCloseAVG= stkCloseAVG + stockClose[i]; 
    minStkClose = stockClose[1]; 
    maxStkClose = stockClose[1]; 
    if (stockClose[i] < minStkClose) 
     minStkClose = stockClose[i]; 
    if (stockClose[i] > maxStkClose) 
     maxStkClose = stockClose[i]; 
} 
cout << "Stock Price" << endl; 
cout << endl; 
cout << "Average" << setw(5) << stkCloseAVG << endl; 
cout << "Minimum" << setw(5) << minStkClose << endl; 
cout << "Maximum" << setw(5) << maxStkClose << endl; 


system("pause"); 
return 0; 
+0

Herkes nasıl düzeltileceğini açıklayabilir *** ne ***? – immibis

+0

Özellikle döngü için. Tüm kodu ekledim, çünkü düzeltmek için neyin gerekli olduğunu bilmiyorum. –

+2

Girdi nedir, beklenen çıktı nedir, gözlenen çıktı nedir? –

cevap

0

Dizelerden dosyaya okuduktan sonra değerleri dizilerinize kaydetmiyorsunuz.

İlgili konular