0

please help me fix these problem,,,,
when i'm running the program it exits emediately

main()/*Start of the function main???*/
{
	do{/*do while loop initialization*/
		print();
		scanf("%c",&choice1);
		switch(choice1){
			case 'A':
			case 'a':
				addContact();
				break;
			case 'F':
			case 'f':
				search(contacts);
				break;
			case 'v':
			case 'V':
				list();
				break;
			case 'e':
			case 'E':
				edit(contacts);
				break;
			default:
				print();
		}
	printf("");
	printf("Do you want to enter another contact?Y/N\n");/*condition question of loop*/
	scanf("%c",&choice2);
	if (choice2 == 'y' || 'Y'){
		choice2 == 'y';
	}else{
		break;
	}
	}while(choice2 ==  'Y' || choice2 == 'y');

}/*end of function main()*/

Edited by Narue: added code tags

3
Contributors
4
Replies
7
Views
6 Years
Discussion Span
Last Post by syria718
0

That's the behavior coded in your snippet.
A possible solution is to use a template like this.

int main(void)
{
    /* your code here */

    getchar(); /* wait until you press a key */
    return 0;
}
0

I don't understand your logic here:

printf("Do you want to enter another contact?Y/N\n");/*condition question of loop*/
	scanf("%c",&choice2);
	if (choice2 == 'y' || 'Y'){
		choice2 == 'y';
	}else{
		break;
	}
	}while(choice2 ==  'Y' || choice2 == 'y');

Accept [I]choice2[/I] If [I]choice2[/I] is eith 'y' or 'Y', change it to 'y' -- this is nonsensical - it's already 'y' or 'Y' otherwise exit the DO-WHILE loop At end of DO-WHILE, test for 'y' or 'Y' -- you just set it to 'y', so you know it must be true. It can't be anything else because if it was you already broke out of the loop. And why test for 'Y'? You set it to 'y' so it can't possibly be 'Y'.

In other words remove the IF statement completely. It's redundant, unnecessary, and extraneous.

Edited by WaltP: n/a

0

That's the behavior coded in your snippet.
A possible solution is to use a template like this.

int main(void)
{
    /* your code here */

    getchar(); /* wait until you press a key */
    return 0;
}

tnXX alot for the help!!<3<3<3

0

I don't understand your logic here:

printf("Do you want to enter another contact?Y/N\n");/*condition question of loop*/
	scanf("%c",&choice2);
	if (choice2 == 'y' || 'Y'){
		choice2 == 'y';
	}else{
		break;
	}
	}while(choice2 ==  'Y' || choice2 == 'y');

Accept [I]choice2[/I] If [I]choice2[/I] is eith 'y' or 'Y', change it to 'y' -- this is nonsensical - it's already 'y' or 'Y' otherwise exit the DO-WHILE loop At end of DO-WHILE, test for 'y' or 'Y' -- you just set it to 'y', so you know it must be true. It can't be anything else because if it was you already broke out of the loop. And why test for 'Y'? You set it to 'y' so it can't possibly be 'Y'.

In other words remove the IF statement completely. It's redundant, unnecessary, and extraneous.

hehehe...tnxX for the help...yeah your right!!!my if statement was too much...i think its because i'm just a new learner...tnxxx for your help more powers..

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.