-3

image

I do not understand why these errors exist about the operands. I also am curious, when I print out "Your bill is...", how do I allow the computer to calculate the bill for me?

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
alex
  • 1
  • 1
  • 1
  • You are comparing a `std::string` to an `int` – drescherjm Mar 03 '21 at 21:33
  • You also have a misplaced `;` on the same line causing the `if ()` to be pointless if the comparison was valid. – drescherjm Mar 03 '21 at 21:34
  • https://idownvotedbecau.se/imageofcode Please do not provide images of code. They can't be searched, copied into compilers, seen by visually-impaired people, etc. Copy/paste your code as actual text instead. – Remy Lebeau Mar 03 '21 at 21:38
  • thank you for the help! I am sorry as this is my first time learning how to write code. @RemyLebeau Do you think that I should delete the string altogether? – alex Mar 03 '21 at 21:42
  • @alex since you are not using it for anything, then yes. It is just wasted memory. – Remy Lebeau Mar 03 '21 at 21:48

1 Answers1

0

Your error is because you are trying to compare an int to a string, which won't work, that comparison is not defined. Besides, your string is empty anyway.

Also, your if has an erroneous ; on the end of it. In fact, your whole if makes no sense and should be removed.

Try this instead:

#inslude <iostream>
using namespace std;

int main()
{
    int TDU, kWh;
    cout << "Who is your TDU?\n";
    cin >> TDU;
    cout << "How many kWh did you use for the month you would like to calculate?\n";
    cin >> kWh;
    cout << "Your bill is " << 3.42 + (0.0384470 * kWh);
    return 0;
}

UPDATE: That being said, you probably meant to do something more like this instead:

#inslude <iostream>
using namespace std;

static const int ONCOR = ...; // <-- for you to fill in as needed...

int main()
{
    int TDU, kWh;
    cout << "Who is your TDU?\n";
    cin >> TDU;
    cout << "How many kWh did you use for the month you would like to calculate?\n";
    cin >> kWh;
    if (TDU == ONCOR)
        cout << "Your bill is " << 3.42 + (0.0384470 * kWh);

    return 0;
}

Alternatively:

#inslude <iostream>
using namespace std;

int main()
{
    string TDU;
    int kWh;
    cout << "Who is your TDU?\n";
    cin >> TDU;
    cout << "How many kWh did you use for the month you would like to calculate?\n";
    cin >> kWh;
    if (TDU == "ONCOR")
        cout << "Your bill is " << 3.42 + (0.0384470 * kWh);

    return 0;
}

Depending on what format you want the user to enter the TDU as.

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
  • Thank you very much for the help! I am trying to calculate electricity bills with various companies for my project. I am new to this and haven't an idea what I am doing. I really appreciate it. – alex Mar 03 '21 at 21:47
  • When I run the program, it works but is not allowing me to enter my kWh. Do you have any idea why that would be? I enter my TDU just fine. Also, I think I need to use if else statements to differentiate electric companies. Is that correct? – alex Mar 03 '21 at 21:50
  • *"is not allowing me to enter my kWh*" - my bad, it was a typo in my example, I have corrected it. "*I need to use if else statements to differentiate electric companies. Is that correct?*" - yes. I have updated my answer to show an example of that. – Remy Lebeau Mar 03 '21 at 21:51
  • You have helped me immensely. Thank you so much! ( : – alex Mar 03 '21 at 22:00