Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

In the C porgraming Language with documentation. Write a program that uses a str

ID: 653849 • Letter: I

Question

In the C porgraming Language with documentation.

Write a program that uses a structure for storing the name of a stock, its estimated earnings per share, and its estimated price-to-earnings ratio. Have the program prompt the user to enter these items for five different stocks, each time using the same structure to store the entered data. When the data have been entered for a particular stock, have the program computer and display the anticipated stock price based on the entered earnings and price-per-earnings values. For example, if a user entered the data XYZ 1.56 12, the anticipated price for a share of XYZ stock is (1.56)*(12) = $18.72.

Sample output:

Explanation / Answer

#include<stdio.h>
#include<conio.h>

struct share{
   char name[50];
   float estErnPrShr;
   int ratio;
};   //declare structure share

void main(){
   struct share s;   //declare an instance s of structure share
   float anticipatedPrice;   //declare float variable to store anticipated price
   int i=0;   //declare an integer for loop variable
   clrscr();   //clear the contents of output window
   for(i=0;i<5;i++){   //loop 5 times
       anticipatedPrice=0;   //initialize anticipated price to 0
       printf("Enter stock name: ");   //prompt user to enter stock name
       scanf("%s",s.name);   //accept the stock name in the variable name of structure s
       printf("Enter estimated earnings per share: ");   //prompt user to enter estimated earnings per share
       scanf("%f",&s.estErnPrShr);   //accept the estimated earnings per share in the variable estErnPrShr of structure s
       printf("Enter price to earnings ratio: ");   //prompt user to enter price to earning ratio
       scanf("%d",&s.ratio);   //accept the price to earning ratio in the variable ratio of structure s
       anticipatedPrice=s.estErnPrShr*s.ratio;   //calculate anticipated price
       printf("The anticipated price for %s is $%.2f ",s.name,anticipatedPrice);   //display the anticipated price in the format 2 digits after decimal point
   }
   getch();   //wait at the console for any key to be pressed
}