#c++ question

1 messages · Page 1 of 1 (latest)

humble night
#

Hi, im very new to c++ syntax, i am trying to run a program but every time i run it it doen't get into the if

include "iostream"

using namespace std;

int main(){
int a = 0, b = 0, vueltas = 0;
cout <<"Enter A and B values respectively. Being A the given money to the cashier and B the cost"<< endl;
cin >> a; // paid
cin >> b; // price
if (a>b) {
// change to be given
cout<<"change to be given"<<endl;
vueltas = a - b;
// having in mind that change options are 5000,2000,1000,500 y 100
if (change>=5000) {
// give change in 5000 ticket
int billetes_5k = vueltas/5000;
vueltas = vueltas%5000;
cout<<"las vueltas despues del módulo:"<< vueltas<< endl;
}
}
else if (b>a){
// money missing
cout<<"Not enought money for paying";

}
else if (b=a){
// No change to be given
cout<<"Money paid and price match, no change needed.";
}

return 0;

}

#

i dont remember how to post like code

#

so my problem is that when i compile it gets to the underlined part, but it does not continue running the "if" that's below.

#

it just stops

#

i dont know why

gloomy river
#

may not be relevant tho , but try to make comparison consistent
you want a > b and a < b
dont make a > b and b > a at same time

humble night
#

technically its the same but different order

#

but ok

gloomy river
#

ofc its the same

#

have you encountered any compile error?

humble night
#

no

#

it runs just fine

gloomy river
#

because just by seeing this main() , i cant find change

humble night
humble night
#

so that there is no confusion

#

but lemme send again

#

include "iostream"

using namespace std;

int main(){
int a = 0, b = 0, change = 0;
cout <<"Enter A and B values respectively. Being A the given money to the cashier and B the cost"<< endl;
cin >> a; // paid
cin >> b; // price
if (a>b) {
// change to be given
cout<<"change to be given"<<endl;
change = a - b;
// having in mind that change options are 5000,2000,1000,500 y 100
if (change>=5000) {
// give change in 5000 ticket
int billetes_5k = change/5000;
change = change%5000;
cout<<"las vueltas despues del módulo:"<< change<< endl;
}
}
else if (b>a){
// money missing
cout<<"Not enought money for paying";

}
else if (b=a){
// No change to be given
cout<<"Money paid and price match, no change needed.";
}

return 0;

}

gloomy river
#

i can run it tho

#

i built it with vs code

#

and then i can run

humble night
#

ye

humble night
# humble night

but the problem is that as seen here, when u get to the "change to be given" cout it doesn't continue with the code below and it just stops

gloomy river
#

thats the end already?

humble night
#

no

gloomy river
#

wait

humble night
#

u can visualize an "if" below the cout of the change

gloomy river
#

this is interesting

#

i havent changed anything

#

i rebuilt it and it just works

humble night
#

i just noticed the problem

#

ill send solution later