Menu() function, choose with Switch() and return to Menu()

Please support our C advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved

Join Date: Dec 2006
Posts: 2,048
Reputation: Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of 
Solved Threads: 179
Aia's Avatar
Aia Aia is offline Offline
Postaholic

Re: Menu() function, choose with Switch() and return to Menu()

 
0
  #11
Dec 26th, 2008
>So for that test code to work it would require a no parameter for( ; ; )?
for( ; ; ) is a needed forever loop that in essence will only stop when
if ( scanf ( "%d", &i ) == 1 ) is true and break;

while(1) could have been used, but there's the added process of while evaluating that 1 which is a little extra step.
Last edited by Aia; Dec 26th, 2008 at 4:00 pm.
"If it moves, tax it. If it keeps moving, regulate it, and if it stops moving, subsidize it" - Ronald Reagan
Reply With Quote Quick reply to this message  
Join Date: Dec 2008
Posts: 18
Reputation: kacete is an unknown quantity at this point 
Solved Threads: 0
kacete's Avatar
kacete kacete is offline Offline
Newbie Poster

Re: Menu() function, choose with Switch() and return to Menu()

 
0
  #12
Dec 26th, 2008
That makes sense, well i understood it completely! Thank you all guys!

I learn more here than in classes! it's all working perfectly now!
Reply With Quote Quick reply to this message  
Join Date: Dec 2008
Posts: 6
Reputation: kikloo is an unknown quantity at this point 
Solved Threads: 0
kikloo kikloo is offline Offline
Newbie Poster

Re: Menu() function, choose with Switch() and return to Menu()

 
0
  #13
Dec 28th, 2008
Hi,

I guess you can also use goto function to return to the menu.

  1. menu:
  2.  
  3. printf "Your menu";
  4.  
  5. // upto you to use switch or scanf
  6.  
  7.  
  8. // when the work is done for choosen option
  9. // just do: goto menu; and it will return to menu

Hope it helps.
Reply With Quote Quick reply to this message  
Join Date: Dec 2006
Posts: 2,048
Reputation: Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of 
Solved Threads: 179
Aia's Avatar
Aia Aia is offline Offline
Postaholic

Re: Menu() function, choose with Switch() and return to Menu()

 
0
  #14
Dec 28th, 2008
>I guess you can also use goto function to return to the menu.
I know without guessing that if you control the flow of the program you don't need a goto in this case.

goto is frown upon because it could jump anywhere making it hard to read and debug. Search for "spaghetti code", if you want to know further.
Last edited by Aia; Dec 28th, 2008 at 2:54 pm.
"If it moves, tax it. If it keeps moving, regulate it, and if it stops moving, subsidize it" - Ronald Reagan
Reply With Quote Quick reply to this message  
Join Date: Dec 2008
Posts: 18
Reputation: kacete is an unknown quantity at this point 
Solved Threads: 0
kacete's Avatar
kacete kacete is offline Offline
Newbie Poster

Re: Menu() function, choose with Switch() and return to Menu()

 
0
  #15
Dec 28th, 2008
Goto is good for batch files, most programmers hate that command.
Reply With Quote Quick reply to this message  
Join Date: Oct 2009
Posts: 1
Reputation: LNF is an unknown quantity at this point 
Solved Threads: 0
LNF LNF is offline Offline
Newbie Poster
 
0
  #16
Oct 28th, 2009
Can ANYONE find a mistake in this! I cant seem to make it work! (nevermind the french comments...)

#include<stdio.h>
#include<stdlib.h>
#include<time.h>
int Imprimer_Menu();
void Execute_Test(int operande1[], int operande2[], int reponse[], int operation, int taille);
void Imprimer_Resultat(int operande1[], int operande2[], int reponse[], int operation, int taille);
int main(){
int OPERATION, TAILLE;
TAILLE=10;
int Op1[TAILLE], Op2[TAILLE], Rep[TAILLE];

printf(printf("Ce programme vous aidera %c pratiquer vos multiplications et vos divisions\n", 133);
do{

OPERATION=Imprimer_Menu(); /*Appel de la fonction Imprimer_Menu*/

Execute_Test(Op1, Op2, Rep, OPERATION, TAILLE); /*Appel de la fonction Execute_Test*/

Imprimer_Resultat(Op1, Op2, Rep, OPERATION, TAILLE); /*Appel de la fonction Imprimer_Resultat*/
system("PAUSE");}
while (OPERATION==1 || OPERATION==2);
return(0);
}

int Imprimer_Menu(){
int choix;
do {
printf("\nMenu 1)Multiplication\n 2)Division\n 3)Sortie\n");
printf("Veuillez choisir une option:");
scanf("%d", choix);}
while(choix>3 || choix<1);
return(choix);}
void Execute_Test(int operande1[], int operande2[], int reponse[], int operation, int taille){
int i;
time_t t;
srand(time(&t));
if (operation==1){

printf("\nR%cpondez aux 10 multiplications suivantes\n", 130);
for(i=0; i<taille; i++) {
operande1[i]=1+rand()%9;
operande2[i]=1+rand()%9;

printf("\n%d X %d=", operande1[i], operande2[i]);
scanf("%d", reponse[i]);}}


else if(operation==2){
printf("\nR%cpondez aux 10 divisions suivantes\n", 130);
for(i=0; i<taille; i++){
operande1[i]=1+rand()%9;
do{
operande2[i]=1+rand()%9;}
while((operande1[i]%operande2[i])!=0);

printf("\n%d / %d=", operande1[i], operande2[i]);
scanf("%d", reponse[i]);}}


else exit(EXIT_FAILURE);
}

void Imprimer_Resultat(int operande1[], int operande2[], int reponse[], int operation, int taille){
int score, i;
score=0;
if (operation==1){
for(i=0; i<taille; i++){
if(reponse[i]=(operande1[i]*operande2[i])){
printf("\n%d X %d = %d - r%cponse correcte", operande1[i], operande2[i], reponse[i], 130);
score++;
}
else
printf("\n%d X %d = %d - r%cponse incorrect, la bonne r%ponse est %d", operande1[i], operande2[i], reponse[i], 130, 130, operande1[i]*operande2[i]);}
}
else{
for(i=0; i<taille; i++){
if(reponse[i]=(operande1[i]/operande2[i])){
printf("\n%d / %d = %d - r%cponse correcte", operande1[i], operande2[i], reponse[i], 130);
score++;
}
else
printf("\n%d / %d = %d - r%cponse incorrect, la bonne r%ponse est %d", operande1[i], operande2[i], reponse[i], 130, 130, operande1[i]/operande2[i]);}
if(score>7)
printf("\nF%clicitations!", 130);
else
printf("\nVeuillez demander de l'aide %c votre enseignant(e)!", 133);
printf("\nVotre score est de %d/%d", score, taille);
}
}
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:




Views: 1966 | Replies: 15
Thread Tools Search this Thread



Tag cloud for C
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC