what is preventing the arithmatic from displaying?

my text file:
Monday Tuesday Wednesday Thursday Friday Saturday Sunday
34252 85776 65746 93453 63534 34335 0
78352 23412 89889 88387 48021 89903 0
98098 73495 12489 84895 30583 28423 0
28942 38942 38475 83753 83729 82742 0


my code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#include <iostream>
#include <fstream>

using namespace std; 
int weightFunction(int, int);
int main(){

 //open input file
 ifstream inFile; 
 inFile.open("Trucks.txt");
 if(!inFile){
             cout<<"Can't open file";
             return 1; 
             } 
             
  //write to file 
 ofstream outFile; 
 outFile.open("TruckFines.txt");
              
 //variables             
 string dayOfWeek[7];
 int truckWeight;  
 int currentWeight, currentDays, currentTruck, currentTruckWeight, result;
 int i, n, d/* day # */,t/* truck #*/, g;
 
 //for loop for inFile 
 for (i = 0; i < 7; i++){
     inFile >> dayOfWeek[i];
     }
 while (inFile){
           for (n = 0; n < 7; n++){
               inFile >> currentDays; 
               }
               }
 //for loop for day 
 for (d = 0; d < 7; d++){
     outFile << "Data for " << dayOfWeek[d]<< ":" << endl; 
     outFile << "Trucks with Fines: " << endl; 
     
 //for loop for trucks    
 for (t = 0; t < truckWeight; t++) {
     currentTruckWeight = truckWeight;

     //function call
     result = weightFunction (d, t); 
     outFile <<  "Truck# " << currentTruck + 1 << "   $" << result << endl;
     
     outFile << "Trucks without fines: " << endl; 
     
     //goes through all trucks 
     for(g = 0; g < truckWeight; g++){
           currentWeight = truckWeight; 
           
            //if current truck is less than or equal to the weight limit
            if(currentWeight <= 80000){
                             outFile << "Truck# " << currentTruck + 1 << endl;; 
                             }
     
     }
     outFile << endl; 
     } 
     }
    system("pause");
    return 0; 
    }

 //function for overweight limit
 int weightFunction(int d, int t){
 
 //variables 
 int currentDay, currentTruck, currentWeight, result; 
 
 //if current truck over limit (limit is 80,000)   
 if (d > 80000){
  result <<((currentWeight - 80000) % 100) * 50; 
} 
  
      return result; 
      }
Lines 30-34. You are looping correctly to read all the numbers from the file, but you store
all of them into a single integer variable (currentDays). An integer can only hold one number
at a time (and it will be the last number you read--0).

That correction will ripple through the rest of your program, so fix the above first.
Topic archived. No new replies allowed.