Help with a code using File I/O and Loops

This is a discussion on Help with a code using File I/O and Loops within the C Programming forums, part of the General Programming Boards category; Oh right. I skimmed 2 & 3, and look hey they are. So you'll need the variables there. They still ...

  1. #16
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Oh right. I skimmed 2 & 3, and look hey they are. So you'll need the variables there. They still serve no purpose in options 4, 5, and 6.

  2. #17
    Registered User
    Join Date
    Oct 2008
    Posts
    14
    right they dont work for 4,5, and 6. But is there any way you can evaluate options 4,5, and 6 in the sample run, and figure out the essentials that i am missing if any to make them run smoothly? Thanks.

  3. #18
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    1. Your for loops, as mentioned previously.
    2. Total_under needs to be initialized to 0.
    3. Your computation of the percentage is backwards (should be total_under * 100.0 / sum).

  4. #19
    Registered User
    Join Date
    Oct 2008
    Posts
    14
    when you say my for loops are incorrect, and you mentioned them earlier, can you point me to where you are referring?

  5. #20
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Quote Originally Posted by bns1201 View Post
    when you say my for loops are incorrect, and you mentioned them earlier, can you point me to where you are referring?
    Quote Originally Posted by tabstop View Post
    -1 is not a valid array index. Your loops shouldn't go from -1 to 0, but from 0 to size.
    I have to type at least four characters or it won't let me post.

  6. #21
    Registered User
    Join Date
    Oct 2008
    Posts
    14
    so should i initialize lowest = 0
    and highest = size?

  7. #22
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Let me show you what the loops for six should look like, since you don't seem to be grasping the last bit here:
    Code:
    if(option==6)
                {
                    printf("What is the target donation?\n");
                    scanf("%d", &target_donation3);
            
                    for(x = 0; x < count; x++)
                    {
                        sum += number[x];
                        if(total_under < target_donation3)
                        {
                            total_under+= number[x];
                        }
                    }
    Notice the complete absence of the words "lowest" and "highest".

  8. #23
    Registered User
    Join Date
    Oct 2008
    Posts
    14
    oooo i see what you mean there. another question, are you running this in a windows native ide?

  9. #24
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    I could be, I suppose. Why?

  10. #25
    Registered User
    Join Date
    Oct 2008
    Posts
    14
    i dont know why but in a mac ide it just doesnt get passed the asking of the file name. So if you were to run it in a windows ide i just wanna see if its working.

  11. #26
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Do you have
    Code:
    fscanf(fin, "&#37;d", &size);
    ?

  12. #27
    Registered User
    Join Date
    Oct 2008
    Posts
    14
    yea thats odd that you should say that cuz i just wrote in fin before, i noticed that it wasnt there

  13. #28
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    In addition, "%d " is a Bad Idea as far as fscanf goes, since if the last number doesn't have a carriage return or something after it, well....

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. file i/o dilemma
    By adramalech in forum C Programming
    Replies: 27
    Last Post: 11-10-2008, 11:30 PM
  2. help on assignment (file i/o)
    By Longhorn9024 in forum C Programming
    Replies: 4
    Last Post: 03-07-2008, 01:08 AM
  3. True ASM vs. Fake ASM ????
    By DavidP in forum A Brief History of Cprogramming.com
    Replies: 7
    Last Post: 04-02-2003, 03:28 AM
  4. simulate Grep command in Unix using C
    By laxmi in forum C Programming
    Replies: 6
    Last Post: 05-10-2002, 04:10 PM
  5. loops and I/O file.
    By Unregistered in forum C++ Programming
    Replies: 3
    Last Post: 09-09-2001, 09:41 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21