Create a program to store weekly expenses and revenues over a period of time. Th
ID: 3809272 • Letter: C
Question
Create a program to store weekly expenses and revenues over a period of time. The program should store the expenses and revenues in two global array variables. Values stored in the array at index k represent the total revenues/expenses recorded during the k^th week. Assume that the maximum number of weeks tracked is 250. Add the following functions to your program: A function that finds the total of all expenses incurred since week t for a given t. A function that records the total expenses and revenues for the next unrecorded week. It must check if there is still space in the array. A function that prints the number of weeks recorded A function that prints all revenues and expenses recorded A function that returns a pointer to the largest revenue recorded Organize the program so the function prototypes are presented first, and the definitions after the main function. Your program should keep asking the user to select one of the following options and execute the corresponding function based on the user choice: computed the total of all expenses, add a new expense/revenue, print the number of weeks recorded, print all revenues and expenses recorded, print the largest revenue recorded, or exit the program. Call your program finances'. Compile and test your program. Make sure your code is properly indented, your variables have meaningful names and macro definitions are used when appropriate. Submit through the handing system the source code finances'Explanation / Answer
#include <stdio.h>
int exp[250];
int revenue[250];
int count=0;
void TotalExpense();
void addExpenseRevenue();
void NumberofWeeks();
void Print();
int* largestReve();
int main(int argc, char const *argv[])
{
int flag=1;
while(flag)
{
printf("A)Compute total of all expenses B)add new expense/revenue C)Print number of weeks recorded D)Print all revenue and expense recorded E)print largest revenue recorded F)Exit ");
char ch;
scanf("%c",&ch);
if(ch=='A')
{
TotalExpense();
}else if(ch=='B')
{
addExpenseRevenue();
}else if(ch=='C')
{ NumberofWeeks();
}else if(ch=='D')
{
Print();
}else if(ch=='E')
{
int *p=largestReve();
printf("%d ", *p);
}
else
{
break;
}
scanf("%c",&ch);
}
return 0;
}
void TotalExpense()
{
int sum=0;
int i;
for ( i = 0; i < count; ++i)
{
sum=sum+exp[i];
}
printf("Total expense is %d",sum);
}
void addExpenseRevenue()
{
printf("enter expense for week %d",count+1);
scanf("%d",&exp[count]);
printf("enter revenue for week %d",count+1);
scanf("%d",&revenue[count]);
count++;
}
void NumberofWeeks()
{
printf("Number of weeks recorded are %d ",count);
}
void Print()
{int i;
for ( i = 0; i < count; ++i)
{
printf("expense for week %d is %d ",i+1,exp[i] );
printf("revenue for week %d is %d ",i+1,revenue[i] );
}
}
int* largestReve()
{
int *p=revenue;
int i;
int max=-99999;
int index;
for ( i = 0; i < count; ++i)
{
if(*p>max)
{
max=*p;
index=i;
}
p++;
}
p=&revenue[index];
return p;
}
====================================================================
Output:
akshay@akshay-Inspiron-3537:~/Chegg$ gcc exp.c
exp.c:3:5: warning: built-in function ‘exp’ declared as non-function [enabled by default]
int exp[250];
^
akshay@akshay-Inspiron-3537:~/Chegg$ ./a.out
A)Compute total of all expenses
B)add new expense/revenue
C)Print number of weeks recorded
D)Print all revenue and expense recorded
E)print largest revenue recorded
F)Exit
B
enter expense for week 1 100
enter revenue for week 1 200
A)Compute total of all expenses
B)add new expense/revenue
C)Print number of weeks recorded
D)Print all revenue and expense recorded
E)print largest revenue recorded
F)Exit
B
enter expense for week 2 300
enter revenue for week 2 400
A)Compute total of all expenses
B)add new expense/revenue
C)Print number of weeks recorded
D)Print all revenue and expense recorded
E)print largest revenue recorded
F)Exit
A
Total expense is 400A)Compute total of all expenses
B)add new expense/revenue
C)Print number of weeks recorded
D)Print all revenue and expense recorded
E)print largest revenue recorded
F)Exit
C
Number of weeks recorded are 2
A)Compute total of all expenses
B)add new expense/revenue
C)Print number of weeks recorded
D)Print all revenue and expense recorded
E)print largest revenue recorded
F)Exit
D
expense for week 1 is 100
revenue for week 1 is 200
expense for week 2 is 300
revenue for week 2 is 400
A)Compute total of all expenses
B)add new expense/revenue
C)Print number of weeks recorded
D)Print all revenue and expense recorded
E)print largest revenue recorded
F)Exit
E
400
A)Compute total of all expenses
B)add new expense/revenue
C)Print number of weeks recorded
D)Print all revenue and expense recorded
E)print largest revenue recorded
F)Exit
F
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.