Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: C++ struct program  (Read 3040 times)

0 Members and 1 Guest are viewing this topic.

COMPCRAZI

    Topic Starter


    Greenhorn

    C++ struct program
    « on: September 07, 2008, 07:54:35 AM »
    Hi guys
    I actually have this assignment that I have to complete:

    Write a C program to ask the user to input an arithmetic expression and store the expression in an array of t records containing the expression, its value and level of difficulty.The user can terminate the input by just pressing <ENTER>
    After inputting , the program will print out all the expressions and their level of difficulty entered by the user.


    This is my program code:
    #include <stdio.h>
    #include <stdlib.h>
    #define SIZE 10

    struct game{
       char exp[10];
       short value;
       short level;

    }quest[SIZE];


    void main(){
       int count,i;
       for(count=0;count<SIZE;count++){
          printf("Please enter the expression:");
          scanf("%s \n",&quest[count].exp);
          printf("Please enter the value of the expression:");
          scanf("%d \n",&quest[count].value);
          printf("Please enter the level of difficulty:");
          scanf("%d",&quest[count].level);
          if(quest[count].exp != '\n');
             break;
       }

       for(i=0;i<count;i++){
          printf("%c %d %d \n",quest.exp,quest.level);
       }


    }


    And belive me I have tried but this just doesn't seem to be working before at least it printed out the first three statements took the input but now it's nowt even doing that it just prints the first statement after that no matter how many times you press enter it doesn't work!!!!
    Please see if you can help me sort it out immediately...it's due tom!!!!THX


    Sidewinder



      Guru

      Thanked: 139
    • Experience: Familiar
    • OS: Windows 10
    Re: C++ struct program
    « Reply #1 on: September 08, 2008, 05:00:30 AM »
    We don't do homework on this site. The official reasoning goes something like this:

    Quote
    If I give you the answer, and you submit it as your own work, your teacher may wrongly think that you are doing fine on the course, and you won't get the remedial attention and extra encouragement you so clearly need. This board does not do lazy kids homework for them.
    Courtesy: Dias de verano

    Of course you and I both know that is a load of crap. This is not about you, it's about us. The real reason ( ;) ;)) is that we can't risk giving you a wrong answer. What if our answer gets you an F? Now, one F in the course of a lifetime is hardly fatal, but imagine our humiliation. How could we ever face the CH membership again? Can you possibly imagine the shame of being stripped of our rankings and starting over as a low-life? Well, can you?

    Now buck up, do your own homework and get the grade you deserve. 8)
    The true sign of intelligence is not knowledge but imagination.

    -- Albert Einstein