COLLABRAINS-Editorials 1

PROBLEM CODE
VIEW2001

PROBLEM LINK:
https://www.codechef.com/QTCC2020/problems/VIEW2001

DIFFICULTY:
Easy

PREREQUISITES:
math

PROBLEM :
Convert a given US dollar amount to Pounds, Lira, Francs, Marks, or Yen.

EXPLANATION:
The first line in the data set is an integer that represents the number of data collections that follow. Each collection consists of an integer US dollar amount followed by the name of the currency to be converted to.
Output a dollar sign ($), the US dollar amount and the words convert to and then the converted amount followed by the currency unit name. If the conversion factor is an integer, output an integer. If it is a decimal, round to 2 decimal places. The output is to be formatted exactly like that for the sample output given below. Assumptions: The US dollar amount is an integer in the range of 1…500. All letters are upper case.
The conversion factors for $1 are:0.84 POUNDS,2040 LIRA,9.85 FRANCS,3.23 MARKS,260 YEN

SOLUTIONS:

Summary

#include<iostream.h>
using namespace std;

void currency_converter (int x, string str)
{
if ( str == “POUNDS” )
cout << x * 0.84 << " POUNDS";

else if ( str == "LIRA" )
    cout << x * 2040 << " LIRA";

else if ( str == "FRANCS" )
    cout << x * 9.85 << " FRANCS";

else if ( str == "MARKS" )
    cout << x * 3.23 << " MARKS";

else
    cout << x * 260 << " YEN";

cout << endl;

}

int main ()
{
int dataset;
scanf (“%d”, &dataset);

while ( dataset-- ) {
    int amount;
    string currency;

    cin >> amount >> currency;

    cout << "$" << amount << " CONVERTS TO ";

    currency_converter (amount, currency);
}

return 0;

}

Feel free to Share your approach.Suggestions are welcomed as always had been. :slight_smile: