I want to make a menu whicch allows the user to select either male or female. if none of those two are selected, the program should print "invalid option". If the user chooses among the two... the program continues. Please help me.
I want to make a menu whicch allows the user to select either male or female. if none of those two are selected, the program should print "invalid option". If the user chooses among the two... the program continues. Please help me.
First try this if it doesn't make obvious sense to you:
That done, consider this:Code:string x; cin >> x; cout << x << endl;
Usually it is easier if you write the code you have tried (or as much as you can, even if it doesn't work) and we comment.Code:if (x[0] == 'X') cout << "correct";
C programming resources:
GNU C Function and Macro Index -- glibc reference manual
The C Book -- nice online learner guide
Current ISO draft standard
CCAN -- new CPAN like open source library repository
3 (different) GNU debugger tutorials: #1 -- #2 -- #3
cpwiki -- our wiki on sourceforge
Code:printf("\n Select the sex (gender) of Subscriber: \n"); printf("\n1. Male"); printf("\n2. Female"); scanf("%s",&s1); char s; FILE *sfPtr; customer sex = {"",""}; /* Here is the error... what to put there? */ char choice; if ((sfPtr = fopen("Subscriber.txt", "w")) == NULL) printf("File could not be opened.\n"); else { for(s=1;s<=1;s++) fwrite (&sex, sizeof(customer), 1, sfPtr); } fclose (sfPtr); printf("\nPlease enter m or f, To exit enter n: "); scanf("%s", &choice); while (choice != 'n') { if ((sfPtr = fopen ("Parent.txt", "rb+"))== NULL) { printf("Unable to open file!!\n"); } else { switch (choice) { case 'M': case 'm': Registration (sfPtr); fclose (sfPtr); break; case 'F': case 'f': Find (sfPtr); fclose (sfPtr); break; default: printf("\nIncorrect choice, Please select a valid option: "); break; } } printf("\nPlease enter m or f, To exit enter n: "); scanf("%s", &choice); } //Subscriber (sfPtr); //Find (sfPtr); fclose (sfPtr);
Why would you put anything there? And is customer a valid type name? (It doesn't appear to be.)
i don't know. :-/ I don't understand the above code. and I just need a very simple way to write a menu. that actually works.
Last edited by Sharie; 04-19-2010 at 10:01 AM.
Presumably you already have an instance of the customer struct running around? You've already gotten name, and address, and ID, etc, right? So just add the response to the .sex field of that struct and you're done. You don't make a brand new customer just for this.