Hi
have done the whole program but now am stuck at what initially seemed like a simple thing a repitation loop
the program is supposed to ask the user if he/ she wants to continue with adding more data - if no exit and continue with the other stuff.

char choice, y, Y, n,  N;

while (choice != N && choice = Y)
{code 
code
code
)

now it keeps coming up with 3 different errors
1 it either just crashes
2 it just keeps doing the stuff of the while loop
3 it keeps telling me choice hasnt been initalized

I have just put in the bits thats causing a problem the rest of the program is fine

Hi
have done the whole program but now am stuck at what initially seemed like a simple thing a repitation loop
the program is supposed to ask the user if he/ she wants to continue with adding more data - if no exit and continue with the other stuff.

char choice, y, Y, n,  N;

while (choice != N && choice = Y)
{code 
code
code
)

now it keeps coming up with 3 different errors
1 it either just crashes
2 it just keeps doing the stuff of the while loop
3 it keeps telling me choice hasnt been initalized

I have just put in the bits thats causing a problem the rest of the program is fine

you need to take choice from user
like scanf("%c",&choice); for the first time then again in the whicle loop..

secondly

while (choice != N && choice = Y) here choice = y is wrong it should be choice == Y

done
I did do the scanf bit forgot to include it here
then I was including the Y and N as 'Y' and 'N'
changed that and the == bit - now it just dosent compile saying some kind of fatal error
lol

char choice, y, Y, n, N;
//no need of declaring y,Y,n,N they r useless
while (choice != N && choice == Y)

didnt see this

here it should have been
while (choice != 'N' && choice == 'Y')
comparision should be done with characters

i cant understand what you r actually trying to do..
can you post your whole code here?

i cant understand what you r actually trying to do..
can you post your whole code here?

// This programe is going to be used to calculate the payroll of employees in a comapany//


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

void main()

{
	
	char choice, N, Y;
	int emp_id;
    
	printf ("Would you like to enter in any more employees: ");
	scanf ("%c%*c", &choice, &Y, &N);
    while ( choice != N && choice == Y)
	{ 
	

	printf ("please enter employee number: ");
	scanf ("%d%*c", &emp_id);
	
	}
	
	
	system("pause");










}

I have taken out the rest of the working within the while loop
just left the emp id bit for an example

k do it like

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

int main()
{
	char choice;
	int emp_id;
    
	printf ("Enter employee Detail :  ");
                do
                {
                              printf ("please enter employee number: ");
	              scanf ("%d", &emp_id);
                              printf("\nDo you want to enter more employees? (Y/N) :");
                              scanf("%c",&choice);
                }while ( choice != 'N');
	system("pause");
                return 0;
}

hey Kunal thanks for that - didnt think of a do ... while loop

but the requirement of the program is to ask if i want to add new employee after every entry - with the solution u just gave me - it just keeps asking for the employee code over and over again - dosent exit at any point

it will exit if you enter N ..
ok previous code had some prob with std i/o

here is new one

# include <stdio.h>


int main()
{
	char choice;
	int emp_id;
    
	printf ("Enter employee Detail :  \n");
    do
    {
          printf ("please enter employee number: ");
          scanf ("%d",&emp_id);
          printf("Do you want to enter more employees? (Y/N) :");
		  while(getchar() != '\n') continue;
		  scanf ("%c",&choice);
          
    }while ( choice != 'N');
	system("pause");
    return 0;
}

hey its me again
i dont know whats the issue it just wont work
am using visual studio as the compiler

I will just post the entire code up
see what u guys think

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

void main()

{
	int emp_id;
	float hours;
	float mon, tue, wed, thur, fri;
	float norm_pay, over1_pay, over2_pay, over_pay;
	char dep_code;
	char choice;

	
	printf("Do you want to enter any more employee details (Y/N): ")
	scanf("%c%*c", &choice);

	do
	{

	printf("Enter employee Id: ");
	scanf("%d%*c", &emp_id);

	printf (" Please enter the hours worked for each day in the week when promted to \n");

	do
	{
		printf ("Please enter the hours worked on Monday: ");
		scanf ("%f.2%*c",&mon);
		if (mon > 12)
		{
			printf("\n Invalid hours were entered, the hours should not exceed 12 hours");
			printf("\n Please enter the hours worked on Monday:");
			scanf ("%f.2%*c",&mon);
		}
		else
			break;
	} while (mon !> 12);

	do
	{
		printf ("Please enter the hours worked on Tuesday: ");
		scanf ("%f.2%*c",&tue);
		if (tue > 12)
		{
			printf("\n Invalid hours were entered, the hours should not exceed 12 hours");
			printf("\n Please enter the hours worked on Tuesday:");
			scanf ("%f.2%*c",&tue);
		}
		else
			break;
	} while (tue !> 12);

	do
	{
		printf ("Please enter the hours worked on Wednesday: ");
		scanf ("%f.2%*c",&wed);
		if (wed > 12)
		{
			printf("\n Invalid hours were entered, the hours should not exceed 12 hours");
			printf("\n Please enter the hours worked on Wednesday:");
			scanf ("%f.2%*c",&wed);
		}
		else
			break;
	} while (wed !> 12);

	do
	{
		printf ("Please enter the hours worked on Thursday: ");
		scanf ("%f.2%*c",&thur);
		if (thur > 12)
		{
			printf("\n Invalid hours were entered, the hours should not exceed 12 hours");
			printf("\n Please enter the hours worked on Thursday:");
			scanf ("%f.2%*c",&thur);
		}
		else
			break;
	} while (thur !> 12);

	do
	{
		printf ("Please enter the hours worked on Friday: ");
		scanf ("%f.2%*c",&fri);
		if (fri > 12)
		{
			printf("\n Invalid hours were entered, the hours should not exceed 12 hours");
			printf("\n Please enter the hours worked on Friday:");
			scanf ("%f.2%*c",&fri);
		}
		else
			break;
	} while (fri !> 12);
	
	hours = mon + tue + wed + thur + fri;

	if (hours < 40)
	{
		norm_pay = hours * 7.5;
	}

	else if (hours > 40 && hours >= 50)
	{
		over1_pay = (hours - 40) * 11.25;
	}

	else ( hours > 50 && hours >= 60)
	{
		over2_pay = (hours - 50) * 15;
	}
	
	over_pay = over1_pay + over2_pay;

    do
	{
		printf (" Please enter the department code of the employee: ");
	    scanf ("%c%*c", &dep_code);
		if (dep_code != 'A' || dep_code != 'D' || dep_code != 'S')
		{
			printf("The code entered is invalid, please enter the department code again.")
			printf("Please enter the department code of the employee: ");
			scanf("%c%*c", &dep_code);
		}
		else 
			break;
	} while (dep_code == 'A' || dep_code == 'D' || dep_code == 'S')

	switch (dep_code)
		case 'A':
			printf ("The employee works in the Administration department");
			break;

		case 'D':
			printf ("The employee works in the Development department");
			break;

		default :
			printf ("The employee works in the Supply department");
			break;

			printf ("The employee code is: %d", emp_id);
			printf("The employee's salary is: %f", norm_pay);
			printf("The employee's overtime salary is: %f", over_pay);
	}while (choice != 'N');


    system("pause");
	return 0;


}

Simpky use if & else conditions

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.