In your favorite open world adventure video game, currency conversion is as given below: 1 Gold coin 23 Bolts 1 Gem 13 Gold coins Write a program that takes a number of Bolts as user input (as an integer) and converts it to the number of whole Gems, Gold coins, and Bolts as shown below. The conversion information between these measurement metrics is provided in the table above. The number of Bolts should be converted in such a way that maximizes the whole number of Gems and Gold coins. Expected output 1 (bold is user input) Enter the number of Bolts: 32 0 Gems(s) 1 Gold coin(s) 9 Bolt(s) Expected output 2 (bold is user input) Enter the number of Bolts: 3000 10 Gem(s) 0 Gold coin(s) 10 Bolt(s) The file should be named as convertCurrency.cpp. Don’t forget to head over to Coderunner on Canvas and paste your solution in the answer box!
In your favorite open world adventure video game, currency conversion is as given below:
1 Gold coin | 23 Bolts |
1 Gem | 13 Gold coins |
Write a program that takes a number of Bolts as user input (as an integer) and converts it to the number of whole Gems, Gold coins, and Bolts as shown below. The conversion information between these measurement metrics is provided in the table above. The number of Bolts should be converted in such a way that maximizes the whole number of Gems and Gold coins.
Expected output 1 (bold is user input)
Enter the number of Bolts: 32 0 Gems(s) 1 Gold coin(s) 9 Bolt(s)
Expected output 2 (bold is user input)
Enter the number of Bolts: 3000 10 Gem(s) 0 Gold coin(s) 10 Bolt(s)
The file should be named as convertCurrency.cpp. Don’t forget to head over to Coderunner on Canvas and paste your solution in the answer box!
Answer:
Code in C++:
#include <iostream>
using namespace std;
int main()
{
int bolt,gem=0,gold=0; //declare veriable
cout<<"Enter the number of Bolts:\n";
cin>>bolt; //take input from user
gold=bolt/23; //find number of gold coin
bolt=bolt%23; //calculate rest bolts
gem=gold/13; //convert gold to gem
gold=gold%13; //calculate rest gold coins
cout<<gem<<" Gem(s) "<<gold<<" Gold coin(s) "<<bolt<<" Bolt(s)"; //print output
return 0;
}
Step by step
Solved in 2 steps with 1 images