read the program, and explain what it does. Place comments appropiately within t
ID: 3632314 • Letter: R
Question
read the program, and explain what it does. Place comments appropiately within the text.#include<stdio.h>
#include<conio.h>
/*main function*/
main()
{
/*declaring variables*/
double sales[5][12];
double monthlySales;
double highestSales=0;
int hYear=0,hMonth=0;
int m,y;
/*file pointer*/
FILE *fp;
clrscr();
/*opening file*/
fp=fopen("input.txt","r");
if(fp==NULL)
{
printf("File not found");
exit(0);
}
for(y=0;y<5;y++)
{
for(m=0;m<12;m++)
{
fscanf(fp,"%lf",&monthlySales);
sales[y][m]=monthlySales;
if(monthlySales>highestSales)
{
hYear = y;
hMonth = m;
highestSales= monthlySales;
}
}
}
printf("Month of Highest Sales: Year %2d, Month %2d , %.2lf Dollars ",hYear+1,hMonth+1,sales[hYear][hMonth]);
printf("Month Before's Sales: Year %2d, Month %2d , %.2lf Dollars ",hYear+1,hMonth,sales[hYear][hMonth-1]);
printf("Month After's Sales: Year %2d, Month %2d , %.2lf Dollars ",hYear+1,hMonth+2,sales[hYear][hMonth+1]);
printf("Year After the Month of Highest Sales: Year %2d, Month %2d , %.2lf Dollars ",hYear+2,hMonth+1,sales[hYear+1][hMonth]);
for(y=0;y<5;y++)
{hMonth=0;
for(m=1;m<12;m++)
{if(sales[y][m]>sales[y][hMonth])
hMonth=m;
}
printf("Highest sales for year %d is month %d with sales of $%.2f ",(y+1),(hMonth+1),sales[y][hMonth]);
}
}
Explanation / Answer
printf("Month of Highest Sales: Year %2d, Month %2d , %.2lf Dollars ",hYear+1,hMonth+1,sales[hYear][hMonth]); printf("Month Before's Sales: Year %2d, Month %2d , %.2lf Dollars ",hYear+1,hMonth,sales[hYear][hMonth-1]); printf("Month After's Sales: Year %2d, Month %2d , %.2lf Dollars ",hYear+1,hMonth+2,sales[hYear][hMonth+1]); printf("Year After the Month of Highest Sales: Year %2d, Month %2d , %.2lf Dollars ",hYear+2,hMonth+1,sales[hYear+1][hMonth]);
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.