Thread: stupid computer class...need help please

  1. #16
    Registered User TheBigH's Avatar
    Join Date
    May 2010
    Location
    Melbourne, Australia
    Posts
    426
    Quote Originally Posted by tayexdrums View Post
    Strahd:
    I chose the last option of changing my macro but now I have the same problem I started with=[
    Leave the quotes in the #define, and go with Strahd's second suggestion. See if that works.
    Code:
    while(!asleep) {
       sheep++;
    }

  2. #17
    Registered User
    Join Date
    Sep 2011
    Posts
    26
    Quote Originally Posted by TheBigH View Post
    Okay, so that's three floats and (I think) an int. Your fscanf needs to read all those in; currently it's only reading in balloonLaunchAngle.
    So how would I put that in syntax?

  3. #18
    Registered User
    Join Date
    Sep 2011
    Posts
    26
    Quote Originally Posted by TheBigH View Post
    Leave the quotes in the #define, and go with Strahd's second suggestion. See if that works.
    Alright, that gives me my output without the error message so I'm getting somewhere!
    There is a picture of what the output looks like in a picture in one of the above posts

  4. #19
    Registered User
    Join Date
    Sep 2011
    Location
    Stockholm, Sweden
    Posts
    131
    Quote Originally Posted by tayexdrums View Post
    So how would I put that in syntax?
    If you would look up the scanf function, you could find out. http://linux.die.net/man/3/scanf

    Hint:
    Code:
    float a, b, c;
    int i;
    fscanf(fp, "%f %f %f %i", &a, &b, &c, &d);

  5. #20
    Registered User
    Join Date
    Sep 2011
    Posts
    26
    that's what I thought it would look like. I guess what I'm asking is how to read in those values with the compiler KNOWING that the first column is the balloonLaunchAngle, second column balloonLaunchVelocity, third throwersHeight, fourth balloonDiameter

  6. #21
    Registered User
    Join Date
    Sep 2011
    Location
    Stockholm, Sweden
    Posts
    131
    Quote Originally Posted by tayexdrums View Post
    that's what I thought it would look like. I guess what I'm asking is how to read in those values with the compiler KNOWING that the first column is the balloonLaunchAngle, second column balloonLaunchVelocity, third throwersHeight, fourth balloonDiameter
    Did actually read how the (f)scanf function works? If you did, then you would know that the first value is stored in variable a, second value in variable b and so on. So what do you want? You want to store the first value into balloonLaunchVelocity (or whichever was the first column in the file) etc. So just change a, b, c and d to your corresponding variable names.

  7. #22
    Registered User
    Join Date
    May 2011
    Location
    Around 8.3 light-minutes from the Sun
    Posts
    1,949
    You tell it that with your fscanf assignments. Replace a,b,c,i with your variables in the fscanf statement.
    Quote Originally Posted by anduril462 View Post
    Now, please, for the love of all things good and holy, think about what you're doing! Don't just run around willy-nilly, coding like a drunk two-year-old....
    Quote Originally Posted by quzah View Post
    ..... Just don't be surprised when I say you aren't using standard C anymore, and as such,are off in your own little universe that I will completely disregard.
    Warning: Some or all of my posted code may be non-standard and as such should not be used and in no case looked at.

  8. #23
    Registered User
    Join Date
    Sep 2011
    Posts
    26
    Right I know that...so the first value will be stored in the variable balloonLaunchAngle, the second value will be stored in the variable balloonLaunchVelocity, the third value will be stored in the variable throwersHeight, the fourth value will be stored in the variable balloonDaimeter. My question is how do you tell it to repeat this? such as when you get to 5, 6 , 7, and 8

  9. #24
    Registered User
    Join Date
    Sep 2011
    Posts
    26
    Right I know that...so the first value will be stored in the variable balloonLaunchAngle, the second value will be stored in the variable balloonLaunchVelocity, the third value will be stored in the variable throwersHeight, the fourth value will be stored in the variable balloonDaimeter. My question is how do you tell it to repeat this? such as when you get to 5, 6 , 7, and 8

  10. #25
    Registered User
    Join Date
    Sep 2011
    Location
    Stockholm, Sweden
    Posts
    131
    Quote Originally Posted by tayexdrums View Post
    Right I know that...so the first value will be stored in the variable balloonLaunchAngle, the second value will be stored in the variable balloonLaunchVelocity, the third value will be stored in the variable throwersHeight, the fourth value will be stored in the variable balloonDaimeter. My question is how do you tell it to repeat this? such as when you get to 5, 6 , 7, and 8
    You are already doing something like that in your code, you have:
    Code:
    while((fscanf(balloonValues,"%f",&poolWater))==1)
    {
        ...
    }
    


    The return value from fscanf is the number if items read, so you could change the value it compares with to either 4 to make sure you always read the four values you need, or EOF to check if it has read to the End Of File. Perhaps even throw in some error handling there in case the file data is corrupted :-)

    Code:
    while ((fscanf(balloonValues, "%f %f %f %i", &balloonLaunchAngle, &balloonLaunchVelocity, &throwersHeight, &balloonDaimeter)) == 4)
    or
    Code:
    while ((fscanf(balloonValues, "%f %f %f %i", &balloonLaunchAngle, &balloonLaunchVelocity, &throwersHeight, &balloonDaimeter)) != EOF)


  11. #26
    Registered User
    Join Date
    Sep 2011
    Posts
    26
    Okay, I see, that makes sense=]
    I'm still getting wrong output though=[

  12. #27
    Registered User
    Join Date
    Sep 2011
    Location
    Stockholm, Sweden
    Posts
    131
    Quote Originally Posted by tayexdrums View Post
    Okay, I see, that makes sense=]
    I'm still getting wrong output though=[
    Can you re-post your new code, along with the generated output and your expected output?

  13. #28
    Registered User
    Join Date
    Sep 2011
    Posts
    26
    Code:
    #include<stdio.h>            //standard library definitions
    #include<stdlib.h>
    #include<math.h>            //math definitions
    #define BAL_HEIGHT 12    //balcony height in feet
    #define G  32               //gravitational acceleration in ft/s2
    #define PI 3.14159
    #define POOL_CENTER 35  //distance to the center of pool
    #define MIN_THETA 5        //minimum balloon launch angle in degrees
    #define MIN_VEL 1            //minimum balloon launch velocity in ft/sec
    #define MIN_THR_HT 4.5    //minimum height of thrower in feet
    #define MAX_THETA 85        //maximum balloon launch angle in degrees
    #define MAX_VEL 30        //maximum balloon launch velocity in ft/sec
    #define MAX_THR_HT 7.0    //maximum height of thrower in feet
    #define MIN_DIAM 3        //minimum diameter of balloon in inches
    #define MAX_DIAM 9        //maximum diameter of balloon in inches
    #define CAPACITY 7        //pool capacity in gallons
    #define FILENAME "balloonValues.txt"    //input data file
    
       int main()
       {
          double balloonLaunchAngle;                    //input: angle in degrees
          double balloonLaunchVelocity;                //input: launch velocity in ft/sec
          double throwersHeight;                        //input: user's height plus balcony height in feet
          double distanceTraveled;                    //output: distance the balloon traveled in feet
          double part1, part2, part3;                //distance formula: partial result holders
          int balloonDiam;                               //ballon diameter in inches
          double balloonWater;                            //amount of water in balloon in gallons
          double poolWater;                            //amount of water in pool in gallons
          int balloonNumThrown;                        //number of balloons "thrown"
          int balloonNumHit;                            //number of balloons that "hit" the pool
           
          FILE *balloonValues;
          balloonValues=fopen(FILENAME,"r");
          if(balloonValues==NULL)
          {
             printf("Error opening input file.");
          }
          else
          {
             poolWater=0;
             balloonNumThrown=0;
             balloonNumHit=0;
             srand(time(NULL));
             while((fscanf(balloonValues,"%f %f %f %d", &balloonLaunchAngle,  &balloonLaunchVelocity,   &throwersHeight, &balloonDiam))!=EOF)
             {
                balloonNumThrown++;
                 
             
                switch(balloonDiam)
                {
                   case 3: balloonWater=0.1;
                      break;
                   case 4: balloonWater=0.2;
                      break;
                   case 5: balloonWater=0.3;
                      break;
                   case 6: balloonWater=0.55;
                      break;
                   case 7: balloonWater=0.8;
                      break;
                   case 8: balloonWater=1.25;
                      break;
                   case 9: balloonWater=1.7;
                      break;
                }
                
                part1=(balloonLaunchVelocity*cos(balloonLaunchAngle*PI/180.0))/G;
                part2=balloonLaunchVelocity*sin(balloonLaunchAngle*PI/180.0);
                part3=2*G*(throwersHeight+BAL_HEIGHT);
                distanceTraveled=part1*(part2+(sqrt(pow(part2,2)+part3)));
                 
                if(distanceTraveled>POOL_CENTER-1 && distanceTraveled<POOL_CENTER+1)
                {
                   poolWater=poolWater+balloonWater;
                   balloonNumHit++;
                }
                if(poolWater<CAPACITY)
                   balloonNumThrown;
             }
            fclose(balloonValues); 
          }
           
           printf("%f\n %f \n%f \n%d\n", &balloonLaunchAngle,  &balloonLaunchVelocity,  
             &throwersHeight, &balloonDiam); //threw that in there just to check that I am getting values
          printf("%d balloons hit the pool.\n", balloonNumHit);
          printf("%d balloons were thrown.\n", balloonNumThrown);
          printf("%.2f %% balloons hit the pool.\n", (double)balloonNumHit/balloonNumThrown*100);
          printf("The pool was full after balloon #%f", poolWater);
          //fclose(balloonValues);
          return(0);
    the output should look like this...but in the directions it says that everyone will probably have different answer
    8 balloons hit the pool.
    275 balloons were thrown.
    2.91% balloons hit the pool.
    The pool was full after balloon #218.
    3.00 gallons of water spilled over the edge of the pool. ( I haven't done this one yet)

  14. #29
    Registered User
    Join Date
    Sep 2011
    Location
    Stockholm, Sweden
    Posts
    131
    Quote Originally Posted by tayexdrums View Post
    Code:
     printf("%f\n %f \n%f \n%d\n", &balloonLaunchAngle,  &balloonLaunchVelocity, &throwersHeight, &balloonDiam);
    You have to remove the &'s from that line. As it is now, it tries to print the memory address of the variables instead of the actual values.

  15. #30
    Registered User
    Join Date
    Sep 2011
    Posts
    26
    oops, okay, now here's what I get everytime I run the program...
    stupid computer class...need help please-untitled-jpg

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Stupid problem probably has a stupid answer...
    By hardcorpsems in forum C Programming
    Replies: 2
    Last Post: 11-01-2009, 06:15 AM
  2. Replies: 6
    Last Post: 08-04-2003, 12:22 AM
  3. Stupid Math Question....really stupid
    By ToLazytoSignIn in forum A Brief History of Cprogramming.com
    Replies: 9
    Last Post: 01-16-2003, 07:36 PM
  4. Stupid Computer Problems!
    By xds4lx in forum A Brief History of Cprogramming.com
    Replies: 8
    Last Post: 05-07-2002, 05:38 PM
  5. stupid computer lab lady...
    By dirkduck in forum A Brief History of Cprogramming.com
    Replies: 7
    Last Post: 10-16-2001, 06:53 PM