I'm trying to run a program with 3 levels:1st Menu, 2nd Input and Output and 3rd Calculations.
But it keeps me giving me permition denied and Id returned 1 exit status when I try to compile. any suggestion?
here is the code

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

int calcpercent (int xx,int yy);
int calclargest (int pp, int rr, int qq);
void percent ();
void large ();
int menu ();

int main ()
{
	int choice;
	choice = menu ();
	while (choice!=3)
	{
		switch (choice)
		{
		case 1:
			{ 
				percent ();
				break;
			}
		case 2:
			{
				large ();
				break;
			}
		default:
			{ 
				printf ("wrong entry!\n");
			}
		}
		choice = menu ();
	}
}

int menu ()
{
	int choice;
	printf("chhoose from the following:\n");
	printf ("(1)calculate percentage.\n");
	printf ("(2)calculate largest.\n");
	printf ("(3)quit.\n");
	scanf ("%d",&choice);
	return choice;
}
/*input and output*/
void percent ()
{
	int x,y;
	printf("enter 2 numbers:\n");
	scanf ("%d%d",&x,&y);
	int result;
	result=calcpercent(x,y);
	printf ("the percentage=%d",&result);
	
}

void large ()
{
	int p,r,q;
	printf ("3 numbers please:\n");\
	scanf ("%d%d%d",&p,&r,&q);
	int insult;
	insult=calclargest (p,r,q);
	printf ("the largest=%d",&insult);
}
/*calculations*/

int calcpercent ()
{
	int xx;int yy;int zz;
	zz=(xx/yy)*100;
	return zz;
}

int calclargest ()
{
	int pp,rr,qq,w;
	if (pp<rr && pp<qq)
		w=pp;
	else
		if (rr<pp && rr<qq)
			w=rr;
		else 
			w=qq;
		return w;
}
Attachments
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int calcpercent (int xx,int yy);
int calclargest (int pp, int rr, int qq);
void percent ();
void large ();
int menu ();

int main ()
{
	int choice;
	choice = menu ();
	while (choice!=3)
	{
		switch (choice)
		{
		case 1:
			{ 
				percent ();
				break;
			}
		case 2:
			{
				large ();
				break;
			}
		default:
			{ 
				printf ("wrong entry!\n");
			}
		}
		choice = menu ();
	}
}

int menu ()
{
	int choice;
	printf("chhoose from the following:\n");
	printf ("(1)calculate percentage.\n");
	printf ("(2)calculate largest.\n");
	printf ("(3)quit.\n");
	scanf ("%d",&choice);
	return choice;
}
int calcpercent ()
{
	int xx;int yy;int zz;
	zz=(xx/(xx+yy))*100;
	return zz;
}
void percent  ()
{
	int x,y;
	printf("enter 2 numbers:\n");
	scanf ("%d%d",&x,&y);
	int result;
	result=calcpercent(x,y);
	printf ("the largest=%d",&result);
	
}
int calclargest ()
{
	int pp,rr,qq,w;
	if (pp<rr && pp<qq)
		w=pp;
	else
		if (rr<pp && rr<qq)
			w=rr;
		else 
			w=qq;
		return w;
}
void large ()
{
	int p,r,q;
	printf ("3 numbers please:\n");\
	scanf ("%d%d%d",&p,&r,&q);
	int result;
	result=calclargest (p,r,q);
	printf ("the largest=%d",&result);
}

Your implementations of calcpercent and calclargest do not have their parameter lists included.

You've declared them before main as taking (int, int) and (int, int, int) parameters respectively.
E.g.:

int calcpercent (int xx,int yy);
int calclargest (int pp, int rr, int qq);

Yet in your actual implementation of the functions, their parameter lists are empty.

int calcpercent () // oops, no parameters!
{
	int xx;int yy;int zz; // xx and yy should be in the parameter list, not here!
	zz=(xx/yy)*100;
	return zz;
}

int calclargest () // oops, no parameters!
{
	int pp,rr,qq,w; // pp, rr and qq should be in the parameter list above
	if (pp<rr && pp<qq)
		w=pp;
	else
		if (rr<pp && rr<qq)
			w=rr;
		else 
			w=qq;
		return w;
}

Because you've omitted the parameter lists from the implementations of calcpercent and calclargest; the compiler/linker will see the two versions with no parameters as separate, valid functions. But it will not be able to find definitions for the two you forward declared which take int parameters. Which WILL cause a linker error, which is exactly what you've reported.

If you move the function parameters into the parameter lists of the implementations of both functions (as indicated in the snippets I posted) your program should compile and link without error.

Also, if you're using an up to date compiler, you should be getting warnings about using scanf. scanf_s is a safer implementation of scanf and should be used if your compiler supports it. If you're using an older compiler and/or you aren't getting any warnings about scanf, then scanf_s probably isn't implemented in your compiler, so don't worry about it!

Other than that the code looks OK to me!

Edited 5 Years Ago by JasonHippy: n/a

I did the steps above and it's compiling with no error, but isn't give me the expected result. I get something like 2686732 for both percentage and largest

I was only really looking for what was causing your linker error yesterday, so I only gave your code a cursory look. But after taking a closer look at your code, I can see a few other problems which I didn't spot yesterday.

1. In the printf statements in your percent() and large() functions, you're outputting the address of the variables result and insult, rather than their actual values. So remove the ampersands (&) before the variable names in your printf statements. That fixes part of the issue with incorrect values being displayed.

2. Your calcpercent function will not produce any useful results because you are using integer mathematics.
So for example, if you entered 5 and 10 as the two values, you would expect it to return 50%. But because you are using ints, your calculation zz=(xx/yy)*100 would actually yield 0.
Because in integer mathematics in C and C++, 5/10 = 0 and 0*100 = 0.
So, you may have to either change the function to take and return float or double values. Otherwise if you require integers to be used, you'll have to cast one or more of the values in the division operation to a floating point value and then cast the final result back to int. e.g.

return (int)(((float)xx/yy)*100);

What that does is, cast xx to a float, so the rest of the percentage calculation will yield a floating point value, which is then cast back to int and returned.

Note: Because you're using C rather than C++, I've used a C-style cast instead of using the C++ static_cast operator.

3. Your 'largest' function will actually return the smallest of the values entered, NOT the largest. This is because you used the 'less than' operator '<' instead of the 'greater than' operator '>'.
So in largest, you'll need to replace all occurrences of '<' with '>'.

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