code not working properly.

this is the code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include <iostream>
using namespace std;
int main(){
    float gasprice = 3.021;
    int paymentmethod, numberofgallons, k;
    cout<<"Please enter your payment method. Press 1 for cash or 0 for credit"<<endl;
    cin>>paymentmethod;
    if(paymentmethod=0){
    cout<<"You have selected credit."<<endl;
}
    else
        cout<<"You have selected cash."<<endl;
    cin>>k;
    
    
    return 0;
}


whenever i compile and run the code, everything works fun, but when i input 0 (for credit) the message displays "you have selected cash" instead of the designated "you have selected credit." i've tried this other ways and i still can't get it to work properly. also, the cin>>k is there so i can view the program work without having it disappear after half a second. if any other information needed, i will be glad to supply it.
if(paymentmethod=0) should it be if(paymentmethod == 0)?
ah, thank you shazlin!
after writing this code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <iostream>
using namespace std;
int main(){
    float gasprice = 3.021;
    int paymentmethod, numberofgallons, k;
    cout<<"Please enter the number of gallons you would like"<<endl;
    cin>>numberofgallons;
    cout<<"Please enter your payment method. Press 1 for cash or 0 for credit"<<endl;
    cin>>paymentmethod;
    if(paymentmethod==0){
    
    cout<<"You have selected credit. Your total is "<<(gasprice*numberofgallons+(numberofgallons*0.10))<<endl;
}
    else
        if(paymentmethod==1){
        cout<<"You have selected cash. Your total is "<<(gasprice*numberofgallons)<<endl;
}
    cin>>k;
    
    
    return 0;
}


i've got what i need, but i need to make the total to two decimal places (xx.xx). my professor told me to use printf instead of cout, but she didn't teach us that yet and i'm completely clueless as to how the syxtax would work if i would replace the couts that display the totals with printfs.
Topic archived. No new replies allowed.