Hi All

I am very new to C and would appreciate your help. I am trying to create a program which reads a file (a list of numbers) and prints to the screen those which are higher than 0.7. Does anyone know how to do this? So far I am able to get the whole file printed to the screen, but not just part of it. I have looked everywhere for examples but no joy.

Thanks

Post what you have so far and we'll try to help you fix it up ;)

Hi All

I am very new to C and would appreciate your help. I am trying to create a program which reads a file (a list of numbers) and prints to the screen those which are higher than 0.7. Does anyone know how to do this? So far I am able to get the whole file printed to the screen, but not just part of it. I have looked everywhere for examples but no joy.

Thanks

Hey, welcome to the right forum.
Post your code pertinent to the question and let us "critic it" for you.

Hi All

I am very new to C and would appreciate your help. I am trying to create a program which reads a file (a list of numbers) and prints to the screen those which are higher than 0.7. Does anyone know how to do this? So far I am able to get the whole file printed to the screen, but not just part of it. I have looked everywhere for examples but no joy.

Thanks

I just wrote this right now so there might be a few errors. :cheesy:

#include iostream
#include fstream
#include string
int main()
{
     int list[100], a, length = 0;
     ifstream inFile;
     inFile.open("filename.ext");
     while(!inFile.eof())
     {
         inFile >> a;
          int i=0;
          list[i] = a;
          i++;
          length++;
     }
     for(int z=0; z<length;z++)
     {
          if(list[z] > 0.7)
          {
               cout << z <<endl;
          }
     }
     system("pause");
     return 0;
}

I just wrote this right now so there might be a few errors. :cheesy:

<snip>

Rather than syntax erros, your implementation seems really inefficient. Why bother saving the values if you're just going to print them? Also, the OP would be dealing with doubles. Comparing an int to 0.7 is the same as comparing it to 0. ;)

Rather than syntax erros, your implementation seems really inefficient. Why bother saving the values if you're just going to print them? Also, the OP would be dealing with doubles. Comparing an int to 0.7 is the same as comparing it to 0. ;)

True but he should be able to get the point and fix it. Thanks though I didn't think of those things.

True but he should be able to get the point and fix it. Thanks though I didn't think of those things.

Another thing you didn't think about is if you do someone's homework for them, they learn nothing, but get a passing grade anyway. Please help them find the solution, don't give it to them.

Another thing you didn't think about is if you do someone's homework for them, they learn nothing, but get a passing grade anyway. Please help them find the solution, don't give it to them.

As they already stated it doesn't do exactly what he asked so he has to understand it to fix it and there is his example but I'll stop giving them "answers".

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.