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

What\'s wrong with my code? i keep getting the following errors: Warning: static

ID: 3620778 • Letter: W

Question

What's wrong with my code? i keep getting the following errors:

Warning: static decleartion of fibonacci follows non-static decleartion
warning: previous decleartion of fibonacci was here
error: "int_max" undeclared (first use in this function)
warning: static ddecleation of reverse follows non-static decleartion
warning: previous declartion of reverse was here
warning: no newline at end of file
error: syntax error at end of input

I'm supposed to create a menu driven system using function pointers. I dont know what i'm diong wrong. Once i create teh menu, the user selects an input and runs one of four programs.


Here is my code:


#include<stdio.h>
#include <string.h>

void dice(); /* module for program 1 */
void series(); /* module for program 2 */
void reverse(); /* module for program 3 */
void patterns(); /* module for program 4 */

int main()
{
int program;/*declare variables */

printf("What whould you like to do? 1 - Simulate the roll of twodice "); /*prompt one*/

printf("2 - The Fibonacci Series "); /*prompt 2*/

printf("3 - Reverse Digits "); /* prompt 3*/

printf("4 - Print Four Patterns "); /*prompt 4*/

printf("5 - Exit "); /*exit choice */

scanf("%d",&program); /* reads user input and stores into variable program */

while(program!=5) /* loop that decides what to do */
{
switch(program)
{
case 1: dice(); /*initiates program 1 */
break;
case 2: series(); /*initiates program 2*/
break;
case 3: reverse(); /*initiates program 3*/
break;
case 4: patterns(); /*initiates program 4*/
break;
default: printf("Error!! TryAgain "); /* allows the user to give another choice*/
}
printf("What whould you like to do? 1 - Simulate the roll of twodice ");
printf("2 - The Fibonacci Series "); /* allows user to reinput choice */
printf("3 - Reverse Digits ");
printf("4 - Print Four Patterns ");
printf("5 - Exit ");
scanf("%d",&program);
}
printf("GOOD BYE!"); /*if input is 5, gives goodbye message and exits */

return 0;
}

void dice() /* code for dice program */
{

int die1;
int die2;
int i;

int tot[10]={0};

srand(time(0));
for(i=0;i<36000;i++)
{
die1=rand()%6;
die2=rand()%6;
tot[die1+die2]++;
}
printf("num count ");
for(i=0;i<=10;i++)
printf("%d %d ",i+2,tot[i]);
return;
}


void series() /*code for fibonacci series program */
{
int fibonacci(int); /* integer variable for fibonacci, defined as integer */
{
int n; /* declares variable n for user input */

int fibnum; /*declares variable fibnum, for the fibonacci module */

printf("Which fibonacci number do you want?"); /* Prompt for user */

scanf("%d",&n); /* returns integer input into variable n */

fibnum=fibonacci(n); /* defines variable fibnum as fibonacci variable */

printf("The %dth fibonacci number is: %d ",n,fibnum); /* prompt return on user input */

fibnum=fibonacci(50000); /*tells the system to generate a large number of fibonacci numbers */

printf("The largest fibonacci number that can be calculated on "); /*returns a value that can be calculated by system */

printf("this system is %d",fibnum); /* allows the preceding prompt to continue on next line */
return;
}

int fibonacci(int n) /* module for variable fibonacci */
{
int first=0; /*variables declared, first, second, next and i */
int second=1;
int next=0;
int i;

for(i=0;i<n-2; i++) /*sets a loop that allows computing until too big */
{
next=first+second;
if(next>INT_MAX||next<0) /* computes until too big, then returns the largest value */
return second;
first=second;
second=next;
}
void reverse() /*code for reverse numbers program */
{
int reverse(int);
int main()
{
int number; /* user input for number */
int reversed; /* variable return for reverse */

printf("Enter a number: "); /*displays prompt and gives a space */
scanf("%d",&number); /* stores user input into number variable */
while(number<1||number>10000) /* sets a loop that doesnt allow input below or above the boundaries */
{printf("Invalid entry must be between 1 and 10000 "); /*prompt that shows the user to reinput value */
printf("Enter a number: "); /* same prompt as above. */
scanf("%d",&number);
}
reversed=reverse(number); /* sets the command. reverses the number retrieved from integer number */
printf("Reversed %04d is %04d ",number,reversed); /* prints the number and then the number reversed */
return; /* exits */
}
int reverse(int n) /* module to define int reverse */
{
int newnum=0;
while(n>0)
{
newnum=newnum*10+n%10; /* sets new number and finds remainder of n */
n=n/10; /* divides n by ten */
}
return newnum; /* returns value nuwnum into int reverse */
}
void patterns() /*taken from previous code */
{

int n,i,j,k;
printf("Enter n: ");
scanf("%d",&n);
k=n;
for(i=1;i<=n;i++){
for(j=1;j<=i;j++)
printf("*");
printf(" ");
}
printf(" ");
for(i=1;i<=n;i++){
for(j=i;j<=n;j++)
printf("*");
printf(" ");
}
printf(" ");
for(i=1;i<=n;i++){
for(j=1;j<=(n-i);j++)
printf(" ");
for(j=1;j<=i;j++)
printf("*");
printf(" ");
}
printf(" ");
k=n;
for(i=1;i<=n;i++){
for(j=n-k;j>=1;j--)
printf(" ");
k--;
for(j=n;j>=i;j--)
printf("*");
printf(" ");

}
return;
}

END OF FILE

Dice is supposed to simulate the rolling of a dice. I believe that is correct.
Series is a fibonacci series program where the user inputs what number they'd like in the series. the program that outputs the fibonacci number and the highest number the computer can process in the series. Patteerns is a program that creates four triangles of different pattern that the user decides how large the triangle is. Reverse is a program that allows the user to input a number and then the program reverses that number.

Can someone review my code and correct it so that it will work. Can you also tell me what i did wrong and explain to me why it is wrong? thank!

Explanation / Answer

please rate - thanks I actually found and fixed an error in dice #include<stdio.h>
#include <string.h>
#include <limits.h>
void dice(); /* module for program 1 */
void series(); /* module for program 2 */
void reverse(); /* module for program 3 */
int reverseit(int);
void patterns(); /* module for program 4 */
int fibonacci(int); /* integer variable for fibonacci, defined as integer */
int main()
{
int program;/*declare variables */
printf("What whould you like to do? 1 - Simulate the roll of twodice "); /*prompt one*/
printf("2 - The Fibonacci Series "); /*prompt 2*/
printf("3 - Reverse Digits "); /* prompt 3*/
printf("4 - Print Four Patterns "); /*prompt 4*/
printf("5 - Exit "); /*exit choice */
scanf("%d",&program); /* reads user input and stores into variable program */
while(program!=5) /* loop that decides what to do */
{
switch(program)
{
case 1: dice(); /*initiates program 1 */
break;
case 2: series(); /*initiates program 2*/
break;
case 3: reverse(); /*initiates program 3*/
break;
case 4: patterns(); /*initiates program 4*/
break;
default: printf("Error!! TryAgain "); /* allows the user to give another choice*/
}
printf("What whould you like to do? 1 - Simulate the roll of twodice ");
printf("2 - The Fibonacci Series "); /* allows user to reinput choice */
printf("3 - Reverse Digits ");
printf("4 - Print Four Patterns ");
printf("5 - Exit ");
scanf("%d",&program);
}
printf("GOOD BYE!"); /*if input is 5, gives goodbye message and exits */
return 0;
}
void dice() /* code for dice program */
{
int die1;
int die2;
int i;
int tot[11]={0};
srand(time(0));
for(i=0;i<36000;i++)
{
die1=rand()%6;
die2=rand()%6;
tot[die1+die2]++;

}
printf("num count ");
for(i=0;i<=10;i++)
printf("%d %d ",i+2,tot[i]);
return;
}
void series() /*code for fibonacci series program */
{
int n; /* declares variable n for user input */
int fibnum; /*declares variable fibnum, for the fibonacci module */
printf("Which fibonacci number do you want?"); /* Prompt for user */
scanf("%d",&n); /* returns integer input into variable n */
fibnum=fibonacci(n); /* defines variable fibnum as fibonacci variable */
printf("The %dth fibonacci number is: %d ",n,fibnum); /* prompt return on user input */
fibnum=fibonacci(50000); /*tells the system to generate a large number of fibonacci numbers */
printf("The largest fibonacci number that can be calculated on "); /*returns a value that can be calculated by system */
printf("this system is %d ",fibnum); /* allows the preceding prompt to continue on next line */
return;
}
int fibonacci(int n) /* module for variable fibonacci */
{int first=0; /*variables declared, first, second, next and i */
int second=1;
int next=0;
int i;
for(i=0;i<n-2; i++) /*sets a loop that allows computing until too big */
{
next=first+second;
if(next>INT_MAX||next<0) /* computes until too big, then returns the largest value */
     return second;
first=second;
second=next;
}
return next;
}
void reverse() /*code for reverse numbers program */
{

int number; /* user input for number */
int reversed; /* variable return for reverse */
printf("Enter a number: "); /*displays prompt and gives a space */
scanf("%d",&number); /* stores user input into number variable */
while(number<1||number>10000) /* sets a loop that doesnt allow input below or above the boundaries */
{printf("Invalid entry must be between 1 and 10000 "); /*prompt that shows the user to reinput value */
printf("Enter a number: "); /* same prompt as above. */
scanf("%d",&number);
}
reversed=reverseit(number); /* sets the command. reverses the number retrieved from integer number */
printf("Reversed %04d is %04d ",number,reversed); /* prints the number and then the number reversed */
return; /* exits */
}
int reverseit(int n) /* module to define int reverse */
{
int newnum=0;
while(n>0)
{
newnum=newnum*10+n%10; /* sets new number and finds remainder of n */
n=n/10; /* divides n by ten */
}
return newnum; /* returns value nuwnum into int reverse */
}
void patterns() /*taken from previous code */
{
int n,i,j,k;
printf("Enter n: ");
scanf("%d",&n);
k=n;
for(i=1;i<=n;i++){
for(j=1;j<=i;j++)
printf("*");
printf(" ");
}
printf(" ");
for(i=1;i<=n;i++){
for(j=i;j<=n;j++)
printf("*");
printf(" ");
}
printf(" ");
for(i=1;i<=n;i++){
for(j=1;j<=(n-i);j++)
printf(" ");
for(j=1;j<=i;j++)
printf("*");
printf(" ");
}
printf(" ");
k=n;
for(i=1;i<=n;i++){
for(j=n-k;j>=1;j--)
printf(" ");
k--;
for(j=n;j>=i;j--)
printf("*");
printf(" ");
}
return;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote