I made this code and i dont know what to do with my warning in calling function calc() inside the function getOption(). What should i do? need some little help here.

#include<stdio.h>

void getOption();
void getData(int *num1, int *num2);
void calc(int option, int num1, int num2);
float add(int num1, int num2);
float sub(int num1, int num2);
float mul(int num1, int num2);
float div(int num1, int num2);
void printResult(float result);

int main()
{

clrscr();
getOption();
getch();
}

void getOption()
{
int option,num1,num2;

clrscr();
printf("[1] Addition\n");
printf("[2] Subtraction\n");
printf("[3] Multiplication\n");
printf("[4] Division\n");
printf("\nChoose options: ");
scanf("%d", &option);
calc(option,num1,num2);

}

void getData(int *num1, int *num2)
{

printf("Enter two integers: ");
scanf("%d %d", num1, num2);
}

void calc(int option, int num1, int num2)
{
switch(option)
{
case 1: clrscr();
printf("\"ADDITION\"\n");
getData(&num1,&num2);
printResult(add(num1,num2));
break;

case 2: clrscr();
printf("\"SUBTRACTION\"\n");
getData(&num1,&num2);
printResult(sub(num1,num2));
break;

case 3: clrscr();
printf("\"MULTIPLICATION\"\n");
getData(&num1,&num2);
printResult(mul(num1,num2));
break;

case 4: clrscr();
printf("\"DIVISION\"\n");
getData(&num1,&num2);
printResult(div(num1,num2));
break;

default: printf("Invalid key");

}
main();
}

float add(int num1, int num2)
{
int add;

add=num1+num2;
return add;
}

float sub(int num1, int num2)
{
int sub;

sub=num1-num2;
return sub;
}

float mul(int num1, int num2)
{
int mul;

mul=num1*num2;
return mul;
}

float div(int num1, int num2)
{
int div;

div=num1/num2;
return div;
}

void printResult(float result)
{
printf("The result is: %.2f", result);
getch();
}

Edited 6 Years Ago by shirmaster: n/a

Please specify your issue.
You mention a warning.. what warning!?

Please indent your code, it is unreadable in it's current state.

I made some fixes, here corrected version:

#include<stdio.h>
#include <stdlib.h>

void getOption();
void getData(int *num1, int *num2);
void calc(int option, int num1, int num2);
float add(int num1, int num2);
float sub(int num1, int num2);
float mul(int num1, int num2);
float divm(int num1, int num2);
void printResult(float result);

void clrscr() {
	// define what is clrscr() - legal on Win
	system("cls");
}

void getch() {
	// getch is non-standard C and should be avoided.
	// use ANSI-C compliant getchar function
	getchar();
}

int main()
{

clrscr();
getOption();
getch();
}

void getOption()
{
// initialize num1,num2 to something
// otherwise you will get runtime error
int option,num1=0,num2=0;

clrscr();
printf("[1] Addition\n");
printf("[2] Subtraction\n");
printf("[3] Multiplication\n");
printf("[4] Division\n");
printf("\nChoose options: ");
scanf("%d", &option);
calc(option,num1,num2);

}

void getData(int *num1, int *num2)
{
printf("Enter two integers: ");
scanf("%d %d", num1, num2);
}

void calc(int option, int num1, int num2)
{
switch(option)
{
case 1: clrscr();
printf("\"ADDITION\"\n");
getData(&num1,&num2);
printResult(add(num1,num2));
break;

case 2: clrscr();
printf("\"SUBTRACTION\"\n");
getData(&num1,&num2);
printResult(sub(num1,num2));
break;

case 3: clrscr();
printf("\"MULTIPLICATION\"\n");
getData(&num1,&num2);
printResult(mul(num1,num2));
break;

case 4: clrscr();
printf("\"DIVISION\"\n");
getData(&num1,&num2);
printResult(divm(num1,num2));
break;

default: printf("Invalid key");

}
// put pause, before repeating user actions
system("pause");
main();
}

float add(int num1, int num2)
{
int add;

add=num1+num2;
return add;
}

float sub(int num1, int num2)
{
int sub;

sub=num1-num2;
return sub;
}

float mul(int num1, int num2)
{
int mul;

mul=num1*num2;
return mul;
}

float divm(int num1, int num2)
{
float div;

div=num1/num2;
return div;
}

void printResult(float result)
{
printf("The result is: %.2f\n", result);
getch();
}

thanks for the help bro... i just thought that initializing num1=0 and num2=0 in function getOption() could affect the calling function.... thanks...

This question has already been answered. Start a new discussion instead.