944,083 Members | Top Members by Rank

Ad:
  • C Discussion Thread
  • Marked Solved
  • Views: 5839
  • C RSS
You are currently viewing page 2 of this multi-page discussion thread; Jump to the first page
Dec 26th, 2008
0

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

>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.
Aia
Reputation Points: 2224
Solved Threads: 218
Nearly a Posting Maven
Aia is offline Offline
2,304 posts
since Dec 2006
Dec 26th, 2008
0

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

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!
Reputation Points: 10
Solved Threads: 0
Newbie Poster
kacete is offline Offline
24 posts
since Dec 2008
Dec 28th, 2008
0

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

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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
kikloo is offline Offline
6 posts
since Dec 2008
Dec 28th, 2008
0

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

>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.
Aia
Reputation Points: 2224
Solved Threads: 218
Nearly a Posting Maven
Aia is offline Offline
2,304 posts
since Dec 2006
Dec 28th, 2008
0

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

Goto is good for batch files, most programmers hate that command.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
kacete is offline Offline
24 posts
since Dec 2008
Oct 28th, 2009
0
Re: Menu() function, choose with Switch() and return to Menu()
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);
}
}
LNF
Reputation Points: 10
Solved Threads: 0
Newbie Poster
LNF is offline Offline
1 posts
since Oct 2009

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C Forum Timeline: need help
Next Thread in C Forum Timeline: passing matrix by ref





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC