When using functions in C, i cannot seem to make my table of options apprear on screen. I have put it in but it will not appear. The options i have put in work fine, for example press 1 to calculate voltage. This works fine and the answer is given back but the grid will not show up on screen.
Here is my code if it is hard to read please say.
void func1 is the table that is supposed to stay on screen until an option is chosen but i cannot seem to have it appear??

#include <stdio.h>
#include <dos.h>

int menu;


void func1();
float func2(float, float);
float func3(float, float);
float func4(float, float);


void func1()
{
  printf("                         ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»\n"); 
  printf("                         º        Main Menu          º\n");
  printf("                         ÌÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ͹\n"); 
  printf("                         ºEnter number of calculationº\n"); 
  printf("                         ÌÍËÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ͹\n"); 
  printf("                         º1º        Voltage          º\n"); 
  printf("                         ÌÍÎÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ͹\n"); 
  printf("                         º2º        Current          º\n"); 
  printf("                         ÌÍÎÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ͹\n"); 
  printf("                         º3º       Resistance        º\n"); 
  printf("                         ÌÍÎÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ͹\n"); 
  printf("                         º4º         EXIT            º\n"); 
  printf("                         ÈÍÊÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ\n");
}


float func2(float I, float R)
{
  float answer;
  answer=I*R;
  return(answer);
}


float func3(float V, float R)
{
  float answer;
  answer=V/R;
  return(answer);
}


float func4(float V, float R)
{
  float answer;
  answer=V/R;
  return(answer);
}


main()
{
  {
    void func1();
  }
  clrscr();
  scanf("%d",& menu);
  if (menu==1)
  {
    float func2(float I, float R);
    float answer;
    float I;
    float R;
    printf("\nEnter Current");
    scanf("%f",& I);
    printf("\nEnter Resistance");
    scanf("%f",& R);
    if(R==0)
    {
      printf("0 IS INVALID");
    }
    else
    {
      answer=I*R;
      printf("\nAnswer is %3.2fAmps x %3.2fOhms = %3.2fVolts",I,R,answer);
    }
    while(!kbhit());
  }
  else if(menu==2)
  {
    float func3(float V, float R);
    float answer;
    float V;
    float R;
    clrscr();
    printf("Enter Voltage\n");
    scanf("%f",&V);
    printf("\nEnter Resistance\n");
    scanf("%f",&R);
    if(R==0)
    {
      printf("0 IS INVALID");
    }
    else
    {
      answer=V/R;
      printf("\nAnswer is %3.2fVolts/%3.2fOhms = %3.2fAmps",V,R,answer);
    }
    while(!kbhit());
  }
}

Recommended Answers

All 3 Replies

You never call the function, you just redeclare it. To call a function you use the name and replace parameters with actual values. For example, here's how you might call each of the functions:

func1();
func2 ( 1.0, 2.0 );
func3 ( V, R );
func4 ( I, R );

hmm i see but i cannot still seem to make function 1 appear as a grid on the start up screen?

I'd wager that you took this:

main()
{
  {
    void func1();
  }
  clrscr();

And without thinking, changed it to this:

main()
{
  func1();
  clrscr();

In which case it makes perfect sense that the menu isn't shown because you show it, then immediately clear it.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.