Using the following variables, translate the conditional statements into one lin
ID: 3920431 • Letter: U
Question
Using the following variables, translate the conditional statements into one line of code in C++ as shown.
if() or while() or for()
You do not know the values of these variables. You are not answering the questions, you are asking the questions. Assume 28 days in a month. Like Harvest Moon, but with goats.
int tTonsOfPotatoes = ?;
int tTonsOfRadishes = ?;
int tGoats = ?;
float tCashOnHand = ?;
float tMonthlyPay = ?;
float tSpinachCostPerPound = ?;
int tMonthsUntilRetirement = ?;
a.) If I will be a millionaire when I eventually retire
b.) If I can feed my goats 5 pounds of spinach a day each for a month with money I have now
c.) If I can afford to buy enough spinach right now to feed each of my goats 5 pounds a day each for a month
d.) For loop to do something to each pair of radish and potato tons. (Hint: the middle part of a for can have an &&.)
e.) While I still have money
f.) While I have goats and I have more potatoes than radishes
int tTonsOfPotatoes = ?;
int tTonsOfRadishes = ?;
int tGoats = ?;
float tCashOnHand = ?;
float tMonthlyPay = ?;
float tSpinachCostPerPound = ?;
int tMonthsUntilRetirement = ?;
a.) If I will be a millionaire when I eventually retire
b.) If I can feed my goats 5 pounds of spinach a day each for a month with money I have now
c.) If I can afford to buy enough spinach right now to feed each of my goats 5 pounds a day each for a month
d.) For loop to do something to each pair of radish and potato tons. (Hint: the middle part of a for can have an &&.)
e.) While I still have money
f.) While I have goats and I have more potatoes than radishes
Explanation / Answer
a)
if(tMonthsUntilRetirement == 0 && tCashOnHand >= 1000000)
b)
if(tCashOnHand >= tGoats *5*tSpinachCostPerPound*28 )
c)
if(tCashOnHand >= tGoats *tSpinachCostPerPound*28 )
d)
for(int i=1;i<= tTonsOfPotatoes && (tTonsOfPotatoes < tTonsOfRadishes); i++)
e)
while(tCashOnHand > 0)
f)
while(tGoats && (tTonsOfPotatoes > tTonsOfRadishes))
Do ask if any doubt. Please upvote.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.