!= doesnt match any operators

If anyone could help me I am writing this program that takes a users amount of money and tells them one possible amount of coins they have. When I try to compile this program in codeblocks I get an error that says;
error: no match for 'operator!=' in 'leave != exit'


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
#include <iostream>
#include <string>
using namespace std;

float money0; //how much money user has
string leave; //used to exit
int dollar;
int quarter;
int dime;
int nickel;
int penny;
const int DOLLAR = 1;
const float QUARTER = 0.25;
const float DIME = 0.10;
const float NICKEL = 0.05;
const float PENNY = 0.01;
int main()
{
    while (true)
    {
    std::cout << "Please enter how much money you have\n";
    std::cin >> money0;
    dollar = money0 /  DOLLAR;
    money0 -= dollar;

        if ( 0 >= money0)
    {
            std::cout << "You have " << dollar << " dollars\n";
            break;
    }

    quarter = money0 / QUARTER;
    money0 -= (quarter * QUARTER);

        if ( 0 >= money0)
    {
            std::cout << "You have $ " << dollar << " and " << quarter << " quarters\n";
            break;
    }

    dime = money0 / DIME;
    money0 -= (dime * DIME);

        if ( 0 >= money0)
    {
            std::cout << "You have $ " << dollar << " and " << quarter << " quarters and " << dime << " dimes\n";
            break;
    }

    nickel = money0 / NICKEL;
    money0 -= (nickel * NICKEL);

        if ( 0 >= money0)
    {
            std::cout << "You have $ " << dollar << " and " << quarter << " quarters and " << dime << " dimes and " << nickel << " nickels\n";
            break;
    }

    penny = money0 / PENNY;

    std::cout << "You have $ " << dollar << " and " << quarter << " quarters and " << dime << " dimes and " << nickel << " nickels and " << penny << " pennies\n";
    std::cout << "Type 'exit' to leave\n";
    std::cin >> leave;
    if (leave != exit)
    std::cout << "Not closing\n";
    else
    break;
}
     return(0);
}

Thanks in advance
I'm not completely sure, but I can spot one error already.
Because leave is a string, you're wanting the user to input "exit" at the end to leave, right? Anyway, to get a string's input, you got to have quotation marks around them. So if you want to get leave, try this.
if (leave != "exit")
I'm new to cpp and I have a small query about this and many other examples that I have been checking out during my research. I didn't want to start a new thread for a small question. Why declare "using namespace std" and then use "std" again in the code?

Also Dark Water Syntax, I'm from a Java background, so it will take me a while to work your problem out, but I think that it's more than just one issue. Someone else will probably work it out quicker than me.

Cheers,

GM

Edit: Ok, I just had a look through your code. Firstly I can't stand "while (true)". It should be something like "while(condition)", i.e. while "(leave != "exit")" (<<< "This is prob not the best example, because you will get an infinite loop if you type in text at the wrong time") and not use "break". I'm working on understanding the purpose of the program and then I should be able to provide a solution, like I said I am new (2 days now, yay).
Last edited on
giantMidget, there really isn't a reason to use std:: if using namespace std; is in place. Not sure why the OP did so, but it can be removed.

Return 0;
OK, cool thanks Return 0;

GM
Topic archived. No new replies allowed.