Setprecision and break problem

1)For some reason my output for total keeps coming out in a high numbers although the math should result in a small number, it happens even though I'm using setprecision.

2)Also the break in my if statement runs even when the condition aren't met, I'm trying to prevent this.

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
#include <iostream>
#include <string>
#include <iomanip>
#include <cmath>


using namespace std;

int main()
{
    double total;
    double vonagePrice = .34,
    skypePrice = .1,
    googlePrice = .3,
    tmoPrice = 1.99;
    int minutes;  //minutes user wants to talk
    string provider, Vonage, Skype, Google, Tmobile;

    Vonage = vonagePrice;
    Skype = skypePrice;
    Google = googlePrice;
    Tmobile = tmoPrice;

               char again;                   // Loop again? Y or N

    cout << "How many minutes would you like to talk? " << endl;
    cin >> minutes;

    cout << "\nProvider " << setw(7) << " Price" << endl;
    cout << "-------- " << setw(7) << " --------" << endl;
    cout << "Vonage " << setw(7) << "$0.34/min" << endl;
    cout << "Skype " << setw(7) << "$0.30/min" << endl;
    cout << "Google " << setw(7) << "$0.30/min" << endl;
    cout << "Tmobile " << setw(7) << "$1.99/min\n" << endl;

    do
    {
        provider = "Vonage" || "Skype" || "Google" || "Tmobile";
        cout << "\nChoose a provider " << endl;
        cin  >> provider;
        if ( provider != "Vonage" || "Skype" || "Google" || "Tmobile" )
        {
            cout << "\nIncorrect input, try again" << endl;
            break;
        }
        else

        total = 'provider' * minutes;

        cout << "You chose " << provider << endl;
        cout << "You wanted to talk for " << minutes << " minutes." << endl;
        cout << fixed << showpoint << setprecision(2);
        cout << "Your total is $" << setprecision(2) << total<< endl;

        cout << "Do you want to see another provider? (Y/N) ";
        cin  >> again;
    }
    while ((again == 'Y') || (again == 'y'));

    return 0;
}
Line 38 and 41 are wrong. It doesn't work like this.
Just remove line 38.
Line 41: if ( provider != "Vonage" || provider != "Skype" || provider != "Google" || provider != "Tmobile" )

Line 48 doesn't make sense. If you want to multiply a factor depending on the provider you need to write it like so:
1
2
3
4
5
if("Vonage" == provider)
  total = some_factor * minutes;
else if("Skype" == provider)
  total = some_other_factor * minutes;
...
Topic archived. No new replies allowed.