Hi im writing a program for a project and dont know why i cant refer to the math1 funtion from inside the void option1(void) function(see below) any insight into this would be appreciated.
Code:
#include <stdio.h>
#include <stdlib.h>
char option, optiona;
void math1(void)
{
system("cls");
printf("This program will calculate total, average and mean\nof a set of numbers you calculate.\n\n");
float x, sum, sq;
int i, n;
printf("How many numbers do you wish to use? ");
scanf("%d", &n);
printf("Please enter number 1: ");
scanf("%f", &x);
sum = x;/*first value entered*/
sq = x*x;
for (i = 2; i <= n; i++)/*i++ OR i = i + 1 OR i += 1*/
{
printf("Please enter number %2d: ", i);
scanf("%f", &x);
sum += x;
sq += x*x;
}
printf("Sum = %10.3f, average = %10.3f, sum of squares = %10.3f\n", sum, sum / n, sq);
}
void option1(void)
{
system("cls");
printf("\t\t*****************\n");
printf("\t\t*Maths Functions*\n");
printf("\t\t*****************\n\n");
printf("Welcome to the maths functions programs.\n\n");
printf("Please select which option you want.\n\n");
printf("1. Program to find the total, average and mean of a set of numbers\n\n");
scanf("%d", &optiona);
if (optiona == '1')
math1();
else if (optiona <= 0 || optiona > 1)
printf("NO!");
}
void option2(void)
{
system("cls");
printf("\t\t*************************\n");
printf("\t\t*Option 2, details later*\n");
printf("\t\t*************************\n\n");
}
void option3(void)
{
system("cls");
printf("\t\t*************************\n");
printf("\t\t*Option 3, details later*\n");
printf("\t\t*************************\n\n");
}
void option4(void)
{
system("cls");
printf("\t\t*************************\n");
printf("\t\t*Option 4, details later*\n");
printf("\t\t*************************\n\n");
}
void option5(void)
{
system("cls");
printf("\t\t*************************\n");
printf("\t\t*Option 5, details later*\n");
printf("\t\t*************************\n\n");
}
void option6(void)
{
system("cls");
printf("\t\t*************************\n");
printf("\t\t*Option 6, details later*\n");
printf("\t\t*************************\n\n");
}
struct personal{
char name[30];
}prs_info;
main()
{
printf("\t\t*********************************************\n");
printf("\t\t*PROGRAMMING PROJECT, SEMESTER 2 (2001/2002)*\n");
printf("\t\t*********************************************\n\n");
printf("Hello, this is a data processing package,\n\n");
printf("Please enter your name so we can get started: ");
fgets(prs_info.name, 30, stdin);
do{
system("cls");
printf("Ok %sPlease choose from the following options (1 - 6)\n\n\n", prs_info.name);
printf("\t1. Maths Functions Package.\n\n");
printf("\t2. File Editing Package.\n\n");
printf("\t3. Option3\n\n");
printf("\t4. Option4\n\n");
printf("\t5. Option5\n\n");
printf("\t6. Option6\n\n");
scanf("%c", &option);
if (option =='1')
option1();
else if (option == '2')
option2();
else if (option == '3')
option3();
else if (option == '4')
option4();
else if (option == '5')
option5();
else if (option == '6')
option6();
}
while (option <= '0' || option > '6');
}