Hi,
My below code compiles and builds ok but it behaves a bit unexpected.

Please see my comment where I am having the problem. Any advice will be highly appreciated.

while(count<9)
   {
	system("cls");
	printf("\n\n\n");
	printf("\t\t\t    PURCHASE ORDER SYSTEM \n\n\n\n\n\n\n\n\n\n\n");
	printf("\t\t\t\t INPUT NEW ORDER DETAILS MENU\n\n\n\n\n\n");
	printf("PLEASE SELECT ONE OF THE GIVEN OPTIONS: \n\n\n\n");
	printf("1) ENTER NEW STYLE DETAILS \n");
	printf("2) BACK TO PREVIOUS MENU \n");
	fgets(userInput, sizeof(userInput), stdin);
	
	
	
	choiceMenuInput=atoi(userInput);
	printf("%d",choiceMenuInput);

	if(choiceMenuInput==1)
// THE CODE IS SUPPOSE TO CHECK CHOICEMENUINPUT AND EXECUTE ACCORDINGLY BUT HE FIRST TIME YOU EXECUTE IT GOES TO THE LAST ELSE.
		input();
	else if(choiceMenuInput==2)
		return 0;
   else
		printf("\n\n\n\n\n ERROR YOU HAVE ENTERED A WRONG CHOICE\n\n\n");
		system("pause");
// IT COMES HERE WHILE EXECUTING.
		inputedit();


    }

Recommended Answers

All 2 Replies

I'd suggest always surrounding blocks with braces until you understand the rules. Properly indenting your code according to how your compiler sees things would produce this:

if(choiceMenuInput==1)
    input();
else if(choiceMenuInput==2)
    return 0;
else
    printf("\n\n\n\n\n ERROR YOU HAVE ENTERED A WRONG CHOICE\n\n\n");

system("pause");
inputedit();

The last two lines are not part of the else clause. You need to wrap the whole thing in braces:

if(choiceMenuInput==1)
    input();
else if(choiceMenuInput==2)
    return 0;
else {
    printf("\n\n\n\n\n ERROR YOU HAVE ENTERED A WRONG CHOICE\n\n\n");
    system("pause");
    inputedit();
}

hi,
I knew my syntax was not wrong but maybe a bit ugly so I searched the net for some documentation on the problem and I found out that the fault was that I was using scanf.

Scanf only takes int the user data not the \n character in the end.

As this is left behind fgets was taking this data and working on it as the user data.

The solution was to use fgets for the previous code also.

Thank you.

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.