CSCI 240 | Fall 2025 |
For this assignment, write a C++ program to calculate the gold per day value of crops grown and harvested from a farming simulation game such as Stardew Valley.
The first thing to do in the program is to create any variables that are needed to hold/save information for the program. To determine how many variables are needed, think about the information that will be entered by someone using the program and whether it is important for that information to be saved. Think about any calculations that will be performed by the program and whether the results of the calculations need to be saved. To determine the data type for the variables, think about what values someone using the program will be entering or what kind of results will be produced by any calculations. (Note: to ease into writing this first program, the data type for the variables has been specified below.)
Ask the user of the program for the gold cost of the seeds necessary to grow this crop. This is value should be saved in an integer variable. The prompt to the user must be "How much does this seed cost to buy?". There should be exactly 1 space after the question mark.
Ask the user of the program for the number of days required for the crop to mature. This is value should be saved in an integer variable. The prompt to the user must be " How long does this crop take to mature?". There should be exactly 1 space after the question mark.
Ask the user of the program for the resale value of the mature crops. This is a value that can have a decimal point and should be saved in a float variable. The prompt to the user must be " What is the expected resale value of the mature crop?". There should be exactly 1 space after the question mark.
Use the three variables from above to calculate how much gold is earned from each day spent watering/waiting for the crop to mature, which is derived from the following formula:
Profit Per Day = (Resale Value of Mature Crop - Cost of the Seed) / Number of Days Until Maturity
Finally, display the calculated profit per day as follows:
The projected profit per day value of this crop is: [profit].
where the [profit] is replaced by the calculated profit per day. There should be exactly 1 space before the calculated profit per day. Make sure the display is preceded by exactly 1 newline character and is ended with exactly 1 newline character.
Name the cpp file that is submitted for grading assign1.cpp.
At the top of the C++ source code, include a documentation box that resembles the following, making sure to replace the “Semester” label with the current semester and year, put your name after the "Programmer" label, the section of CSCI 240 that you're in after the "Section" label, and the due date for the program after the "Date Due" label. A box similar to this one will be put in EVERY source code file that is handed in this semester.
Note: DO NOT put this box within cout statements. It should NOT be displayed as part of the output from the program.
/*************************************************************** CSCI 240 Program 1 Semester Programmer: Section: Date Due: Purpose: This program calculates and displays the profit per value of harvested crops as done in farming simulation video games. ***************************************************************/
Include line documentation. There is no need to document every single line, but logical "chunks" of code should be preceded by a line or two that describes what the "chunk" of code does. This will be a part of every program that is submitted for the remainder of the semester.
Include the following lines of code BELOW the documentation box:
#include <iostream> #include <iomanip> using namespace std;
Use the data types specified above for the cost of the seed, the number of days to harvest, the reale value of the mature crop, and (if used) the calculated profit per day value. Use variable names that clearly indicate the values that they're holding.
Test the program with values other than the ones supplied in the sample output.
Hand in a copy of the source code (the CPP file) on the autograder and Blackboard.
A few runs of the program should produce the following results:
How much does this seed cost to buy? 200 How long does this crop take to mature? 4 What is the expected resale value of the mature crop? 400 The projected profit per day value of this crop is: 50
How much does this seed cost to buy? 324 How long does this crop take to mature? 7 What is the expected resale value of the mature crop? 995.25 The projected profit per day value of this crop is: 95.8929
How much does this seed cost to buy? 100 How long does this crop take to mature? 10 What is the expected resale value of the mature crop? 100.50 The projected profit per day value of this crop is: 0.05
When the program is run on the autograder, the output will resemble the following. Notice that the input values are not displayed.
How much does this seed cost to buy? How long does this crop take to mature? What is the expected resale value of the mature crop? The projected profit per day value of this crop is: 50