Ex. 1- Simple I/O in C++ Write a short C++ program which prompts the user for th
ID: 3919566 • Letter: E
Question
Ex. 1- Simple I/O in C++ Write a short C++ program which prompts the user for the current year, the user's current age, and another year. The program should calculate the age that the user was or will be in the second year entered Input: three lines, the current year on the first, the current age on the second, and the other year on the third Output: one line showing the calculated age PART 2 Write a short C++ program which displays a menu for the user to choose between converting US dollars into Chinese RMB and Chinese RMB into US dollars. The user inputs the amount and the precision, then the program display the corresponding result. Note: use 1.00 USD = 6.20350 CNY as the exchange rate Precision means "how many digit are expected in the final result", e.g. 123.456 has precision 6 · Input: three lines, the first one being 1 for USD or 2 for CNY, the amount on the second one, and the precision on the third one; Output: one line showing the result of the conversion;Explanation / Answer
PART -1
Ans.
#include<bits/stdc++.h>
using namespace std;
int main()
{
int curr_yr, curr_age, next_yr, next_age;
cin>>curr_yr>>curr_age>>next_yr;
next_age = curr_age + (next_yr - curr_yr) ;
cout<< next_age;
return 0;
}
PART- 2
Ans.
#include<bits/stdc++.h>
using namespace std;
int main()
{
int usdORcny, amount, precision;result;
cin>>usdORcny>>amount>>precision;
if(usdORcny == 1)
{
result = amount * 6.2035 ;
}
else
{
result = amount / 6.20350;
}
cout<<std::setprecision(precision)<<result<<endl;
return 0;
}
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.