#include <iostream>
using namespace std;
int main() {
double exchangeRate;
double amountInDollars;
cout << "Currency Converter" << endl;
cout << "------------------" << endl;
cout << "Enter exchange rate (1 USD to your currency): ";
cin >> exchangeRate;
if (exchangeRate <= 0) {
cout << "Invalid exchange rate. Please enter a positive value." << endl;
return 1; // Exit with an error code
}
cout << "Enter amount in USD: $";
cin >> amountInDollars;
if (amountInDollars < 0) {
cout << "Invalid amount. Please enter a positive value." << endl;
return 1; // Exit with an error code
}
double convertedAmount = amountInDollars * exchangeRate;
cout << "Equivalent amount in your currency: " << convertedAmount << endl;
return 0; // Exit successfully
}
출력 결과
Currency Converter
------------------
Enter exchange rate (1 USD to your currency): 0.85
Enter amount in USD: $100
Equivalent amount in your currency: 85
이 예제에서는 사용자가 환율 0.85(1달러를 해당 통화의 0.85로 환산)와 금액 $100을 입력했습니다.
프로그램은 해당 금액을 사용자 통화로 계산하여 표시했으며, 이 경우 85입니다.
'Programming language > C++' 카테고리의 다른 글
[C++] 소수 판별 프로그램 (0) | 2023.10.06 |
---|---|
[C++] palindrome 예제 소스코드 (0) | 2023.10.06 |
[C++] 행맨(Hang man) 구현하기 (0) | 2023.10.06 |
[C++] 텍스트 편집기 구현하기 (0) | 2023.10.06 |
[C++] To-Do Program 개발하기 (1) | 2023.10.06 |