Can someone tell me why this wont work?

This code is designed to let users create their own estimates for pricing and for some reason, the grandTotal function doesn't work right, any thoughts??

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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
#include <iostream>
#include <fstream>
#include <string>
#include <stdlib.h>
#include <windows.h>
using namespace std;

int main () {
  ofstream myfile;
    myfile.open ("Invoice.txt");

    cout << "Enter your name: " << endl << endl;
    string customerFirst;
    getline(cin,customerFirst);
    myfile << "Opacity Software - Invoice for " << customerFirst << endl << endl;

        system("CLS");


    cout << "Enter the amount of hours spent in total that" << endl << "it may take to repair"
    " the device." << " (also use this" << endl << "tool to calculate"
    " remote support hours you may need," << endl << "and only use whole numbers):" << endl << endl;

        int hours;
        cin >> hours;
        int hoursTotal;

    if(hours > -1){
    myfile << "Price for Hours spent: $" << 10 * hours;
    hoursTotal = hours * 10;
        }
    else {
        hoursTotal = 0;
                myfile << endl << "Price for Hours spent: $0";
        }
        system("CLS");



     cout << "Would you like virus removal?:" << endl << endl;

        string virus;
        cin >> virus;
        int virusTotal;

            if (virus=="yes"){
                virusTotal = 35;
    myfile << endl << "Price for virus removal: $35";
            }
            else if (virus=="Yes"){
                 virusTotal = 35;
    myfile << endl << "Price for virus removal: $35";
            }
            else if (virus=="YES"){
                 virusTotal = 35;
    myfile << endl << "Price for virus removal: $35";
            }
            else if (virus=="y"){
                 virusTotal = 35;
    myfile << endl << "Price for virus removal: $35";
            }
            else if (virus=="Y"){
                 virusTotal = 35;
    myfile << endl << "Price for virus removal: $35";
            }
            else{
                 virusTotal = 0;
    myfile << endl << "Price for virus removal: $0";
            }
        system("CLS");



     cout << "Would you like physical cleaning of the device?:" << endl << endl;

        string pClean;
        cin >> pClean;
        int pCleanTotal;

            if (pClean=="yes"){
                pCleanTotal = 10;
    myfile << endl << "Price for physical cleaning: $10";
            }
            else if (pClean=="Yes"){
                pCleanTotal = 10;
    myfile << endl << "Price for physical cleaning: $10";
            }
            else if (pClean=="YES"){
                pCleanTotal = 10;
    myfile << endl << "Price for physical cleaning: $10";
            }
            else if (pClean=="Y"){
                pCleanTotal = 10;
    myfile << endl << "Price for physical cleaning: $10";
            }
            else if (pClean=="y"){
                pCleanTotal = 10;
    myfile << endl << "Price for physical cleaning: $10";
            }
            else{
                pCleanTotal = 0;
    myfile << endl << "Price for physical cleaning: $0";
            }
        system("CLS");

    cout << "Would you like, or need, a new Operating System?:" << endl << endl;

        string oS;
        cin >> oS;
        int oSTotal;

            if (oS=="yes"){
                oSTotal = 60;
    myfile << endl << "Price for Operating System installation: $60";
            }
            else if (oS=="Yes"){
                oSTotal = 60;
    myfile << endl << "Price for Operating System installation: $60";
            }
            else if (oS=="YES"){
                oSTotal = 60;
    myfile << endl << "Price for Operating System installation: $60";
            }
            else if (oS=="Y"){
                oSTotal = 60;
    myfile << endl << "Price for Operating System installation: $60";
            }
            else if (oS=="y"){
                oSTotal = 60;
    myfile << endl << "Price for Operating System installation: $60";
            }
            else{
                oSTotal = 0;
    myfile << endl << "Price for Operating System installation: $0";
            }
        system("CLS");


        cout << "Would you like a full data backup?:" << endl << endl;

        string dataBackup;
        cin >> dataBackup;
        int dataBackupTotal;

            if (dataBackup=="yes" || dataBackup=="YES" || dataBackup=="Y" || dataBackup=="Yes" || dataBackup=="y" || dataBackup=="yEs" || dataBackup=="yeS"){
                dataBackupTotal = 40;
                myfile << endl << "Price for full data backup: $40";
            }
            else {
                dataBackupTotal = 0;
                myfile << endl << "Price for full data backup: $0";
            }

        system("CLS");


        cout << "would you like a data backup(My Docs only)?:" << endl << endl;

        string dataBackupMD;
        cin >> dataBackupMD;
        int dataBackupMDTotal;

            if (dataBackupMD=="yes" || dataBackup=="y" || dataBackup=="Y" || dataBackupMD=="YES" || dataBackupMD=="Yes" || dataBackupMD=="yEs" || dataBackupMD=="yeS"){
                dataBackupMDTotal = 40;
                myfile << endl << "Price for My Documents backup: $40";
            }
            else {
                dataBackupMDTotal = 0;
                myfile << endl << "Price for My Documents backup: $0";
            }

            system("CLS");


        cout << "Do you need any software installed?" << endl << endl;

        string softwareInstall;
        cin >> softwareInstall;
        int softwareInstallTotal;

            if (softwareInstall=="yes" || softwareInstall=="y" || softwareInstall=="Y" || softwareInstall=="Yes" || softwareInstall=="YES" || softwareInstall=="yEs" || softwareInstall=="yeS"){
                softwareInstallTotal = 15;
                myfile << endl << "Price for software installation: $15";
            }
            else {
                softwareInstallTotal = 0;
                myfile << endl << "Price for software installation: $0";

            }

            system("CLS");


    cout << "Enter the number of hours that may be spent on software training.:" << endl << endl;

    int sHours;
    cin >> sHours;
    int sHoursTotal;

        if(sHours > -1){
            myfile << endl << "Price for software training: $" << 10 * sHours;
            sHoursTotal = sHours * 10;
            }
         else {
             sHoursTotal = 0;
                myfile << endl << "Price for software training: $0";
            }

        system("CLS");


        cout << "Enter the number of hours that may be spent on hardware installation:" << endl << endl;

    int hHours;
    cin >> hHours;
    int hHoursTotal;

        if(hHours > -1){
            myfile << endl << "Price for hardware installation $" << 10 * hHours;
            hHours = hHoursTotal * 10;
            }
         else {
             hHoursTotal = 0;
                myfile << endl << "Price for hardware installation $0" << endl;
            }

    int grandTotal;

   grandTotal == hoursTotal + virusTotal + pCleanTotal + oSTotal + dataBackupTotal + dataBackupMDTotal + softwareInstallTotal + sHoursTotal + hHoursTotal;

            myfile << endl << endl << "Total: " << grandTotal;


                myfile << endl << endl << "Phone: 815.277.9187" << endl;
                myfile << "Email: OpacityTech@live.com" << endl << endl << endl;


        system("CLS");


char ch;

  ifstream in("invoice.txt", ios::in | ios::binary);
  if(!in) {
    cout << "Cannot open file.\n";
    return 1;
  }

  while(in) { // in will be false when eof is reached
    in.get(ch);
    if(in) cout << ch;
  }

  in.close();

cout << "There is also a document titled invoice.txt" << endl << "in the folder"
                " where this program is located," << endl << "that contains this"
                "information in plain text." << endl << endl;

system("PAUSE");

  myfile.close();


  return 0;
}
In what way does it not work? What are the values of hoursTotal, virusTotal, pCleanTotal, oSTotal, dataBackupTotal, dataBackupMDTotal, softwareInstallTotal, sHoursTotal and hHoursTotal at the point where grandTotal is calculated?
they are supposed to be whatever the user ends up determining, if the cin of pClean is yes the PCleanTotal becomes 10 but if the user enters anything else it should be 0 and at the end it should add everything up, right now it always gives me -2 no matter what i do.
== is not the same as =
Last edited on
Why don't you make a function that checks whether a std:string
is equal to yes - in whatever combination/case the letters occur.
It would be neater than having all those
checks like
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
           if (virus=="yes"){
                virusTotal = 35;
    myfile << endl << "Price for virus removal: $35";
            }
            else if (virus=="Yes"){
                 virusTotal = 35;
    myfile << endl << "Price for virus removal: $35";
            }
            else if (virus=="YES"){
                 virusTotal = 35;
    myfile << endl << "Price for virus removal: $35";
            }
            else if (virus=="y"){
                 virusTotal = 35;
    myfile << endl << "Price for virus removal: $35";
            }
            else if (virus=="Y"){
                 virusTotal = 35;
    myfile << endl << "Price for virus removal: $35";
            }
            else{
                 virusTotal = 0;
    myfile << endl << "Price for virus removal: $0";
            }

scattered through the program.
im not talking about that part, im having a problem with parts like

hours * 10 = hoursTotal; I think at least, can someone just try working it out? the rest of it works fine
I wasn't really pointing out where the error was (although Moschops did point out an actual error) - I was merely suggesting a tidy up.
ty guys
where are you speaking of = not being equal to == i mean, yes i know but where am i using it wrong?
I see it on line 229
btw guestgulkan

i did fix that problem by using if (virus=="y" || virus=="yes") stuff like that late on
solved changed grandTotal == to =
Topic archived. No new replies allowed.