No Output

Hello, I have an assignment I am working on and I've looked through everything and I cannot find why I am getting no output. I made sure that my files are in the same directory of my program.

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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
  #include <iostream>
#include <fstream>
#include <string>
#include <sstream>
#include <cmath>
#define CURRENTYEAR 2021
#define HIGHWAYTAX 2
using namespace std;
int getYearDifference(int cuyear,int year){
   return cuyear-year;
}
int getreductionpercentage(int cuyear,int year){
   return 10*(cuyear-year);
}
int getbasefees(string type){
   if(type=="Truck"){
       return 500;
   }
   else if(type=="CAR" || type=="SUV"){
       return 100;
   }
   else
   return 200;
}
int main(){
   ifstream file("VehicleInput.txt");
   ofstream outfile("OutputFile.numbers");
   outfile<<"Types of Vehicle,Base Fees,New Base fees IF any surcharge,fees reduction in %, Base fees after reduction,TAX,HIghway Charges,Total Base fees\n";
    string str;
    while (getline(file, str))
    {
        stringstream check1(str);
        string token;
        string lineargs[6];
        int index=0;
        int basefees;
        while(getline(check1, token, ' '))
        {
           cout<<token<<" ";
           lineargs[index]=token;
           index++;
        }
        cout<<"\n";
        outfile<<lineargs[0]+",";
           basefees=getbasefees(lineargs[0]);
           outfile<<basefees<<",";
            cout<<"Base charge is "<<basefees<<endl;
               if(basefees==500){
                   stringstream con(lineargs[5]);
                   int weight = 0;
                   con >> weight;
                       if(weight>1200){
                           basefees=(basefees*22)/100+basefees;
                           outfile<<basefees<<",";
                           cout<<"New base fees is after adding 22% surcharge ::"<<basefees<<endl;
                       }
                       else
                       outfile<<"NO Change,";
      
               }
               else
               outfile<<"NO Surcharge,";
  
      
           stringstream con(lineargs[4]);
           int year = 0;
           con >> year;
           if(getYearDifference(CURRENTYEAR,year)>=7){
               int feesred=70;
               outfile<<feesred<<",";
               cout<<"Base fees reduction in % is "<<feesred<<" because of age "<<(CURRENTYEAR-year)<<endl;
               basefees=(basefees*(100-feesred))/100;
               outfile<<basefees<<",";
               cout<<"After Reduction new base fees is "<<basefees<<endl;
           }
           else if(getYearDifference(CURRENTYEAR,year)>=1){
               int feesred=getreductionpercentage(CURRENTYEAR,year);
               outfile<<feesred<<",";
               cout<<"Base fees reduction in % is "<<feesred<<" because of age "<<(CURRENTYEAR-year)<<endl;
               basefees=(basefees*(100-feesred))/100;
               outfile<<basefees<<",";
               cout<<"After Reduction new base fees is "<<basefees<<endl;
           }
           else{
               outfile<<"NA,NA,";
               cout<<"NO Base fees reduction because of age 0"<<endl;
           }
           int tax=(basefees*6.5)/100;
           cout<<"Tax Added to base fees is "<<tax<<endl;
           cout<<"Highway Tax is "<<HIGHWAYTAX<<endl;
           basefees=basefees+tax+HIGHWAYTAX;
               outfile<<tax<<",";
               outfile<<HIGHWAYTAX<<",";
               outfile<<basefees<<",\n";
           cout<<"Final BASE Fees after adding TAX and Highway charges is "<<basefees<<endl;
           cout<<"************************"<<endl;
    }
       outfile.close();
}
WHY did you start a new topic when you have an open one already?

http://www.cplusplus.com/forum/beginner/281105/
Second post, got tags and a coherent question. Not bad, really, but we do prefer to keep one thread per program next time. For now lets just get you rolling again..

what do you mean, no output? I see cout statements, do they fire? Is no file created? What OS and compiler are you using?
A few things that could happen to files and output:
- output can vanish on some OS that pop up a terminal window and then close it. Its so fast now, you don't even get to blink and its gone. a bogus cin statement at the end of the program is a simple way to solve it (cin >> dummyvariable;)
- files may not be created if you lack permission to write in the target folder.
- files may not be where you think they are. EG if this is visual studio, it could be in the /debug or /release target folder. If you use the filename explicitly it will fix that, that is, use the whole path and filename all together and it will go where you said. If you just say 'blah.txt' the compiler can trick you.

see if any of that helps?
> I made sure that my files are in the same directory of my program.
Would that be the same directory as your source code.
Or the same directory as your executable file.

Search your project directory structure for OutputFile.numbers
Because that's where your VehicleInput.txt should be located for this to work.

Also, posting a few example lines of VehicleInput.txt would be a good idea if you want us to even attempt debugging what the bulk of your code does.
After attempting to open a file, you should always check that the open has been successful. In general, any return value that may indicate a failure should always be checked.

After L26:

1
2
if (!file)
    return (cout << "Cannot open input file\n"), 1;


and similar for after L27.
Topic archived. No new replies allowed.