+2

What did i code wrong

Argentina +10 XP You are in a hat store in Argentina! The prices are listed in US Dollars and Argentinian Pesos. You have both, but you want to make sure you pay the lower price! Do you pay in Dollars or Pesos? The exchange rate is 2 cents for every Peso. Task Create a program that takes two prices and tells you which one is lower after conversion. Input Format Two integer values, the first one is the price in Pesos and the second one is the price in Dollars. Output Format A string that says which currency you should make the purchase in ('Dollars' or 'Pesos'). Sample Input 4000 100 Sample Output Pesos Iwrote the below code for the question above but 2 test cases came out wrong can anybody point me my problem #include<iostream> using namespace std; int main() { float f = 0.2; int Pesos; int Dollars; int c = Pesos*f; cin>>Pesos>>Dollars; if(c<Dollars){ cout<<"Pesos"<<endl; } else{ cout<<"Dollars"; } return 0; }

3/24/2020 3:47:42 PM

Immortal Soul

30 Answers

New Answer

+4

//Immortal Soul see this compare with yours.. #include<iostream> using namespace std; int main() { int Pesos, Dollars; cin>>Pesos>>Dollars; int c = Pesos*0.02; if(c<=Dollars){ cout<<"Pesos"<<endl; } else{ cout<<"Dollars"; } return 0; }

+1

int c=pesos*f; What is the value of pesos here.. It takes garbage value. Always Assign value before using.. Next You taking input for Pesos.. So you need to Interchange these statements. And what is 0.2 multiply logic here.. And when both equal also you need to print Pesos. So use <= instead of <.

+1

You can tag C++ for your thread. Your snippet is written in C++, so it is relevant to tag C++ 👍 (Edit) Code coach also makes a reasonable tag.

+1

jayakirshna Int c=pesos*f here pesos is equal to the input value of the users input . And its 0.2 multiply logic. Cuz it says the "2 cents for every pesos" in the question And i didn't understand what u meant by u need to interchange these statements. Thank u.

0

Instructions are evaluated as they are written in sequence and results stored into stack for later usage purposes. int c=pesos*f; Here Pesos have no value assigned yet. So Pesos value is undefined here. In next statement input is taken for Pesos. After cin>>Pesos ; pepos assigned with input value. Here I say Interchange means you first write input statement after that int c=pesos*f; Exchange statement sequence of those two.. Exchange rate is 2 means Pesos *2 : Dollor. (2:1) Means Dollar*2/100=pesos First do this by your approach of 0.2. Then check by this.....

0

Try to solve it in c++ and u will see if i am right or wrong #jaya krishna

0

Immortal Soul Ok. Ingore about last point.. Iam not tested only calculated that so now ingore. But am not tested your logic also. What about remaining corrections? Do you checked it? Or Do you think those are also not correct?

0

I know that u have c++ skills so pls try both mine and ur codes mine will pass 3 test cases and fail 2 test cases

0

Urs failed the whole 5 test cases

0

OK. Now I wrongly calculated it. Actually I did it with intiger values... (Peso/50) 2/100= 0.02 // i was wrong, not 0.5, 0.02 Immortal Soul Iam asking for all Remaining code corrections? Reprovements with previous one..... And correct one is 0.02 not 0.2

0

So did it pass the whole 5 case tests

0

Yes. Are you not checking it?..

0

Ya i assigned the value of pesos*0.02 but it still faild the 2 test cases

0

Can I see your updated code?

0

#include<iostream> using namespace std; int main() { float f = 0.02; int Pesos; int Dollars; int c = Pesos*f; cin>>Pesos>>Dollars; if(c<=Dollars){ cout<<"Pesos"<<endl; } else{ cout<<"Dollars"; } return 0; } This was my updated code

0

You are not understood my first reply, read again 2nd (same explanation).. cin>>Pesos>>Dollors; //this first, next is int c=Pesos*f;

0

Ya i got it now

0

pesos=400 dollar=10 pes_d=pesos*.02 if pes_d<= dollar: print("Pesos") else: print("Dollars") Language : python What's wrong with it?

0

You have to take the input first then you can apply currency conversion logic.

0

Like this pesos=int(input('Enter number')) dollar=int(input('Enter number')) pes_d=pesos*.02 if pes_d<= dollar: print("Pesos") else: print("Dollars") Language : python What's wrong with it?