+ 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; }

24th Mar 2020, 3:47 PM
Immortal Soul
Immortal Soul - avatar
32 ответов
+ 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; }
24th Mar 2020, 6:07 PM
Jayakrishna 🇮🇳
+ 3
B H Akash remove the strings inside the input field.
30th Nov 2021, 10:47 AM
Pythonist
Pythonist - avatar
+ 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 <.
24th Mar 2020, 4:11 PM
Jayakrishna 🇮🇳
+ 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.
24th Mar 2020, 4:20 PM
Ipang
+ 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.
24th Mar 2020, 4:23 PM
Immortal Soul
Immortal Soul - avatar
+ 1
B H Akash you are needed to remove those text inside of input()... Your code is perfectly working its just Solo learn playground errors pesos=int(input()) dollar=int(input()) pes_d=pesos*.02 if pes_d<= dollar: print("Pesos") else: print("Dollars")
20th Sep 2021, 11:44 AM
JOHN G JAMES
JOHN G JAMES - avatar
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.....
24th Mar 2020, 4:33 PM
Jayakrishna 🇮🇳
0
Try to solve it in c++ and u will see if i am right or wrong #jaya krishna
24th Mar 2020, 4:55 PM
Immortal Soul
Immortal Soul - avatar
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?
24th Mar 2020, 5:11 PM
Jayakrishna 🇮🇳
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
24th Mar 2020, 5:14 PM
Immortal Soul
Immortal Soul - avatar
0
Urs failed the whole 5 test cases
24th Mar 2020, 5:14 PM
Immortal Soul
Immortal Soul - avatar
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
24th Mar 2020, 5:21 PM
Jayakrishna 🇮🇳
0
So did it pass the whole 5 case tests
24th Mar 2020, 5:28 PM
Immortal Soul
Immortal Soul - avatar
0
Yes. Are you not checking it?..
24th Mar 2020, 5:50 PM
Jayakrishna 🇮🇳
0
Ya i assigned the value of pesos*0.02 but it still faild the 2 test cases
24th Mar 2020, 5:56 PM
Immortal Soul
Immortal Soul - avatar
0
Can I see your updated code?
24th Mar 2020, 5:58 PM
Jayakrishna 🇮🇳
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
24th Mar 2020, 6:12 PM
Immortal Soul
Immortal Soul - avatar
0
You are not understood my first reply, read again 2nd (same explanation).. cin>>Pesos>>Dollors; //this first, next is int c=Pesos*f;
24th Mar 2020, 6:15 PM
Jayakrishna 🇮🇳
0
Ya i got it now
24th Mar 2020, 6:18 PM
Immortal Soul
Immortal Soul - avatar
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?
25th Mar 2020, 6:45 PM
B H Akash
B H Akash - avatar