need help asap please

my code compiles but I get error : "FATAL ERROR - CAN NOT OPEN FILE shoppers.dat"

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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
 
// -------------------------------------------------------------------------------
// COP 3014C Fundamentals of Programming
// Assignment ID:   PROG6a
// Due Date: 10/20/12 at 11 pm
// File name:   coupons_c.cpp
//
// Author:   bfields Byron Fields
// 
// Purpose:    You are shopping at your favorite store. You select one item 
//             of merchandise marked at its regular price. At the checkout, 
//             you are asked whether you have a coupon. If  you do not, you 
//             will be charged the regular price. If you have a coupon, the 
//             cashier will determine whether it is a cash-off coupon, or 
//             a percent-off coupon. A cash-off coupon will reduce the regular
//             price by a fixed cash amount; a percent-off coupon will reduce 
//             the price by a percentage of the regular price.
//  
// Author: bfields Byron Fields
//    
//  NOTE:        This is the FIRST STEP in the evolution of this program.
//               ONE SHOPPER / keyboard INPUT / console OUTPUT
//---------------------------------------------------------------------------------

#include <iostream>
#include <fstream>
#include <iomanip>

using namespace std;

int main()
{
cout << "(c) 2012, bfields Byron Fields" << endl;


float regularPrice;
char couponUsed;
char couponType;
float couponValue;  // percent is entered as a whole number.
float Savings;
float amountPaid;
ifstream shopperF("shoppers.dat");
ofstream logF("shoppers.log");
ofstream reportF("redemption.rpt");
float itemPrice_Sum;
float Savings_Sum;
float amtPaid_Sum;


shopperF.open("shoppers.dat");
logF.open("shoppers.log");
reportF.open("redemption.rpt");



if (shopperF.fail())
{
cout << "FATAL ERROR - CAN NOT OPEN FILE shoppers.dat" << endl;
       exit(1); 
}



reportF << "                  COUPON USAGE" << endl;
reportF << "             =======================" << endl;
reportF << "ITEM_PRICE   TYPE  VALUE     SAVINGS    AMT_PAID" << endl;
reportF << "==========   ==== ======  ==========  ==========" << endl;



itemPrice_Sum = 0;
Savings_Sum = 0;
amtPaid_Sum = 0;



while(shopperF >> regularPrice >> couponUsed)
{



if(couponUsed == 'Y' || 'y')
{
shopperF >> couponType >> couponValue;



Savings = 0;



switch(couponType)
{
case 'C' : Savings = couponValue;
           break;
case 'P' : amountPaid = regularPrice * couponValue/100.0;
           break;
default : cout << ' ' << endl;
}



amountPaid = regularPrice - Savings;



reportF << regularPrice << couponType << couponValue << Savings << amountPaid << endl;



logF << regularPrice << couponUsed << couponType << couponValue << amountPaid << endl;

itemPrice_Sum =+ regularPrice;
Savings_Sum =+ Savings;
amtPaid_Sum =+ amountPaid;
}
else
{



amountPaid = regularPrice;



logF << regularPrice << couponUsed << amountPaid << endl;
}
}

 

reportF << setw(10) << right << fixed << setprecision(2) << regularPrice << "     " << couponType << "   " << fixed << setprecision(2) << couponValue << "  " << setw(10) << right << Savings << fixed << setprecision(2) << setw(10) << right << amountPaid << endl;       
reportF << "$ " << setw(8) << right << fixed << setprecision(2) << itemPrice_Sum << "        " << "$ " << fixed << setprecision(2) << Savings_Sum << "  $ " << fixed << setprecision(2) << amtPaid_Sum << endl;       




shopperF.close();
logF.close();
reportF.close();

return 0;
}
Make sure you actually have a 'shoppers.dat' file in the directory your working in.
yes I just checked the repository and shoppers.dat is there
Is shoppers.dat in the same directory of your executable? How do you run it?
yes . im in unix so i did

: g++ coupons_c.cpp -o coupons_c.run

then ./coupons_c.run
Well, I'm using a MinGW shell but I can compile and execute just fine using that procedure. I'm lost
Topic archived. No new replies allowed.