please I need extra credit as well CS 120 02 Chapter D4 Programming Assignment 2
ID: 3601811 • Letter: P
Question
please I need extra credit as well
CS 120 02 Chapter D4 Programming Assignment 20 Points Nant . Due Friday, October 27, 2017 Write a program that predicts the approsimate soe of a populution cf or shouls ask the user to ereer the sarting namber a percentage, for example, assume the user enters the fo lowing values organisms The of organisms, the average daly population iscrease (as esample, 50%) and the number of days the organises will be left to aiyar tarting number of organisms: 2 Average daily increase 30 Number of éays to multiply 10 The program shouls display the following table of ata Approsimate Population 3.38 4-394 T122 .42586 9,653419 16.31462 21.209 1 0 Add the folowing comments to the beginning of the pregra CS 12002 rogram Assigerment 04 Cass and Section Due Oate Program Description You wrbe a short deseription af what the program wil do 1 Tum in a pristout of she source cede with this sheet attached to the front 4 Copy the foider to the tolowing location: tHkoppsbaVcS 120 azyour name where your name is When you complete tte program, do the folawing. 2. Create a folder with the following name Progam 04 1. Copy your program to this folder folder located in ikoppuinbox CS 12002 Extra Credit 5 points Add an average daly decrease percentage. Check to make sure that the decrease percentage is not larger than the increase percentage. Ifit is, ask the user to reenter until they get a correct value Calculate and subtract the average decrease after you calculate and add the average increaseExplanation / Answer
Please find the C code with comments below:
#include <stdio.h>
/*
Name :
Cass & Section: CS 120 02
Assignment: Program Assignment 04
Due Date: Oct 27, 2017
Description: The program will complute the increase in popultation on a daily basis & display the results of each day
*/
int main()
{
float startNum, inc; ///starting number & increase percentage
int days; //number of days
//Input all values
printf("Starting number of Organisms: ");
scanf("%f", &startNum);
printf("Average Daily Increase: ");
scanf("%f", &inc);
printf("Number of days to multiply: ");
scanf("%d", &days);
printf(" Day Approximate Population ");
//Calculate population increase & display
for (int i=0;i<days;i++)
{
printf("%d %f ",i+1,startNum);
startNum+= ((inc*startNum)/100);
}
return 1;
}
Output:
Starting number of Organisms: 2
Average Daily Increase: 30
Number of days to multiply: 10
Day Approximate Population
1 2.000000
2 2.600000
3 3.380000
4 4.394000
5 5.712200
6 7.425860
7 9.653619
8 12.549705
9 16.314615
10 21.209000
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.