#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Posts
    5
    Rep Power
    0

    Help with project for school


    As a final project for a programming class, I have to write a program where the user chooses one out of around 100 small programs we didin class (I have to first show a list like this:
    Week 1, Week 2, etc., have them pick one and then show another list with the programs made in that week, and have them pick one of those) and then ask wether to show its code or execute it.

    What I started doing was making functions like this:

    void p11 (int x){
    if(x==1){
    int a;
    printf("Dame la calificacion:");
    scanf("%i",&a);
    a>=65?printf("Aprobado."):
    printf("Reprobado.");
    system("pause");}
    else if (x==2){
    fp=fopen("E:\\semana_9\\sem1parte1.1.c", "r");
    while ( fgets(s,100,fp) != NULL ){
    fgets(s,100,fp) ;
    fprintf(stdout, "%s", s);
    }
    fclose(fp);}
    }

    If they picked the first program of the first week i would call this function.
    After the first if statement is the small program we did in class. If the second if statement evaluates to true then it reads that program's .c file and prints out its content.

    Inside my main function I would have this:

    for(i=1;i<17;i++){
    printf("%i. Semana %i\n",&i);
    }
    printf("Elija una opcion: ");
    scanf("%i",&sem);
    for(i=1;i<10;i++){
    printf("%i. Programa %i\n",&i);
    }
    printf("Elija una opcion: ");
    scanf("%i",&prg);

    (semana=week,programa=program,elija una opcion=choose an option)

    then I would ask wether to show or execute it (execute x=1, show x=2) and have something like this:

    switch(sem){
    case 1:
    switch(prg){
    case 1:
    p11(x);
    break;
    case 2:
    p12(x);
    break;
    }
    }

    It would take me ages to finish this, Im starting to realize... Is there an easier way to go about it? Kind of a vague question, I know, but Im just looking to cut down the work from any angle... I would really apreciate any help!!!
    Last edited by nawsx; November 26th, 2012 at 08:05 PM. Reason: clarity
  2. #2
  3. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,841
    Rep Power
    480
    Write a few of these functions

    void p11 (int x){

    until you comprehend what they have in common, then write one function that generalizes all of them. Pass the changing information as function parameters.

    Replace your long, fixed case statement with an array and a bit of logic. Looks like you populate the array with a directory list.
    [code]Code tags[/code] are essential for python code and Makefiles!

IMN logo majestic logo threadwatch logo seochat tools logo