| | |
Menu() function, choose with Switch() and return to Menu()
Please support our C advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved |
>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 whenif ( 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
•
•
Join Date: Dec 2008
Posts: 6
Reputation:
Solved Threads: 0
Hi,
I guess you can also use goto function to return to the menu.
Hope it helps.
I guess you can also use goto function to return to the menu.
C Syntax (Toggle Plain Text)
menu: printf "Your menu"; // upto you to use switch or scanf // when the work is done for choosen option // just do: goto menu; and it will return to menu
Hope it helps.
>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.
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
•
•
Join Date: Oct 2009
Posts: 1
Reputation:
Solved Threads: 0
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);
}
}
#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);
}
}
![]() |
Similar Threads
- need a little help...problemis in highlighted area (C++)
- Help, I don't think I'm asking for much. This is a simple java program. (Java)
- Help with hangman tutorial. (C++)
- Menu help please - Newbie (C)
- C programming - need some help (C)
- help to debug my (C++)
- help to debug my code (C++)
- Linked Lists stresses (C++)
- how to call this function...using menu..! (C++)
- The Calculator (C++)
Other Threads in the C Forum
- Previous Thread: need help
- Next Thread: passing matrix by ref
Views: 1966 | Replies: 15
| Thread Tools | Search this Thread |
Tag cloud for C
#include * .net array arrays asterisks binarysearch calculate changingto char cm command copyimagefile cprogramme creafecopyofanytypeoffileinc database directory dynamic execv fflush file fork forloop framework functions getlasterror givemetehcodez grade graphics gtkwinlinux hacking histogram homework inches include incrementoperators input iso kernel keyboard km lazy linked linkedlist linux list lists locate logical_drives looping loopinsideloop. lowest matrix microsoft motherboard mqqueue mysql number opendocumentformat opensource overwrite owf pattern pdf performance pointer pointers posix problem probleminc process program programming radix recursion recv research reversing scanf scripting segmentationfault sequential socket socketprograming spoonfeeding standard string structures student systemcall testing threads turboc unix user variable voidmain() wab whythiscodecausesegmentationfault windowsapi







