Answer the question
In order to leave comments, you need to log in
How to improve (remake) the currency convector in C++?
Hello.
I'm learning C++ from Barjane Stroustrup's book.
Got a job - Write a program to convert hryvnia, rubles and yuan into dollars.
Wrote this "miracle"
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
using namespace std;
int main()
{
// Перевод гривен, рублей, юаней в доллар
// Использование инструкции "if"
setlocale(LC_CTYPE, "Russian_Russia.1251");
double UAH = 28.29, RU = 74.12, CNY = 6.52; // стоимость валют за 1 доллар
int dollar; // единица для перевода
char currenty = ' ';
cout << "Введите валюту и единицу, для перевода\n";
cin >> dollar >> currenty;
if (currenty == 'u')
{
cout << "Стоимость " << dollar << "$ в UAH составит(" << dollar * UAH << ").";
}
if (currenty == 'r')
{
cout << "Стоимость " << dollar << "$ в RU составит(" << dollar * RU << ").";
}
if (currenty == 'c')
{
cout << "Стоимость " << dollar << "$ в CNY составит(" << dollar * CNY << ").";
}
}
Answer the question
In order to leave comments, you need to log in
You are doing nonsense, licking the drill on the operator.
Postpone optimizations and prettiness at least until the end of the tutorial.
Now, with a barely started base, you can only pick up strange ideas, which you will then have to get rid of, relearning.
For example, try to get rid of ifs and variables for each currency. Hint - you need to use the correct collection for this case.
As a whole, it will go like this (if the task, as you said, is on ifs).
In general, from criticism / recommendations:
1.
Write a program to convert hryvnia, rubles and yuan into dollars.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question