• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 240
  • Last Modified:

creation of header files in c++

Here is my code for a small application to create header file and use it..but i am getting some error can any one suggest me what to do

time.h
.................

#include<stdio.h>
#include<math.h>
void main()
{

void secondstominutes();
void minutestohours();
void hourstodays();

}
void secondstominutes()
{
int value;
float min;
printf("\n give the value");
scanf("%d",&value);
min= (float)(value)/60;
min=ceil(min);
printf("\n%d min",min);
}
void minutestohours()
{
int value;
float hours;
printf("\n give the value");
scanf("%d",&value);
hours = (float)(hours)/60;
hours = ceil(hours);
printf("\n%d hours",hours);
}
void hourstodays()
{
int value;
float days;
printf("\n give the value");
scanf("%d",&value);
days=(float)(value)/24;
days=ceil(days);
printf("\n%d days",days);

}




....................
time.c
..........

#include<stdio.h>
 #include"time.h"
{
int choice, value;
printf("\n give choice\n 1. Convert seconds into minutes\n 2. Convert minutes into hours\n 3. Convert hours into days");
scanf("%d",&choice);
      if(choice==1)
      {

      secondstominutes();

      }
      else if(choice==2)
      {

      minutetohours();
      }
      else if(choice==3)
      {

      hourstodays();
      }
}
0
sharath123in
Asked:
sharath123in
2 Solutions
 
_corey_Commented:
I'm afraid to ask what the error is but that design is very flawed.

1) Don't put the function implementation in the header like that.

2) Don't put the main function in the header, put that in the source.

3) What is your source?  It's just bracketed code, that needs to go into the main file and remove those function declarations out of the main().

4) You've misspelled minutestohours in one of the calls.

5) In the minutestohours() function body, you were using the variable 'hours' without initializing it.  You should have been using the variable 'value'.

Here is some fixed up source below, I didn't test or check functionality but it compiles.


[test.h]

#ifndef TEST_H
#define TEST_H


void secondstominutes();
void minutestohours();
void hourstodays();


#endif /* TEST_H */

[test.c]

#include "test.h"
#include <stdio.h>
#include <math.h>


int main()
{
    int choice, value;
    printf("\n give choice\n 1. Convert seconds into minutes\n 2. Convert minutes into hours\n 3. Convert hours into days");
    scanf("%d",&choice);
    if(choice==1)
    {
        printf("\n give the value");
        scanf("%d",&value);
        secondstominutes(value);
    }
    else if(choice==2)
    {
        printf("\n give the value");
        scanf("%d",&value);
        minutestohours(value);
    }
    else if(choice==2)
    {
        printf("\n give the value");
        scanf("%d",&value);
        hourstodays(value);
    }
    return 0;
}

void secondstominutes()
{
    int value;
    float min;
    printf("\n give the value");
    scanf("%d",&value);
    min= (float)(value)/60;
    min=ceil(min);
    printf("\n%d min",min);
}

void minutestohours()
{
    int value;
    float hours;
    printf("\n give the value");
    scanf("%d",&value);
    hours = (float)(value)/60;
    hours = ceil(hours);
    printf("\n%d hours",hours);
}

void hourstodays()
{
    int value;
    float days;
    printf("\n give the value");
    scanf("%d",&value);
    days=(float)(value)/24;
    days=ceil(days);
    printf("\n%d days",days);
}


corey
0
 
jkrCommented:
You should not put any actual code in the header file. Try

time.h
.................

#include<stdio.h>
#include<math.h>

void secondstominutes();
void minutestohours();
void hourstodays();




....................
time.c
..........

#include<stdio.h>
#include"time.h"


void secondstominutes()
{
int value;
float min;
printf("\n give the value");
scanf("%d",&value);
min= (float)(value)/60;
min=ceil(min);
printf("\n%d min",min);
}
void minutestohours()
{
int value;
float hours;
printf("\n give the value");
scanf("%d",&value);
hours = (float)(hours)/60;
hours = ceil(hours);
printf("\n%d hours",hours);
}
void hourstodays()
{
int value;
float days;
printf("\n give the value");
scanf("%d",&value);
days=(float)(value)/24;
days=ceil(days);
printf("\n%d days",days);

}


void main()
{
int choice, value;
printf("\n give choice\n 1. Convert seconds into minutes\n 2. Convert minutes into hours\n 3. Convert hours into days");
scanf("%d",&choice);
    if(choice==1)
    {

    secondstominutes();

    }
    else if(choice==2)
    {

    minutetohours();
    }
    else if(choice==3)
    {

    hourstodays();
    }
}
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now