2016-04-01 9 views
0

私は旅行販売プログラム(STLを使用しないで)に取り組んでいますTSPマトリックスなぜ私の結果は常に0ですか?

これは私に正しい答えを与えるべきではないことを知っています。私は私の行列が正しく読み込まれていることを確認しようとしています。

誰でも問題を見ることができますか?

注:行から複数​​の文字を読み取るにはどうすればよいですか?実際にはスポット6から始まるキャラクターが必要です。

//method for getting the minimum cost of the given routes. 

void getCost(){ 

for(int i = 0; i <50; i++){ 


for(int j = 0; j <50; j++){ 

    if (graph[i][j]>0) 
     totalCost == totalCost + graph[i][j]; 


    } 

} 

} 

    switch (line[0]) { 

     case 'c': 


     cCount++; 

     cout << "Added City: " << line << "\n"; 

     break; 

     case 'a': 

     aCount++; 

     c1 = line[2]; 
     c2 = line[4]; 
     cost = line[6]; 
     cout << "Added Route: " << line << "\n"; 
     graph[c1][c2] == cost; 



     break; 

     default: 

     getCost(); 
     cout << totalCost; 

     stop = true; 
     break; 
    } 

答えて

0

以下は比較であり、割り当てではありません。

totalCost == totalCost + graph[i][j]; 

これを修正するには、

totalCost = totalCost + graph[i][j]; 

または、同等が、より簡潔

totalCost += graph[i][j]; 
+0

を書き、私がいることでしたが、それはまだそこにあるどうやら0を返す:それはtotalCostを変更しません複数の問題 – Remixt

+0

@ClaytonBrant:同じ問題を 'graph [c1] [c2] == cost'に修正しましたか? – NPE

+0

はい、私は2行4と6行に要素があることを確認するためにチェックしました。 – Remixt

関連する問題