fizz buzz

So this is a question from codeeval. which is fizz buzz. The link is here(https://www.codeeval.com/browse/1/) I get a wrong answer cannot understand why. I did a sample run and it runs fine.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include<iostream>
#include<fstream>
#include<string>
using namespace std;

int main(int argc, char * argv[])
{

    int a,b,c;
    ifstream file;
    if(argc > 1)
    {
        file.open(argv[1]);
    }

    while (!file.eof())
    {
       file >> a;
       file >> b;
       file >> c;

       if(file.eof())
        break;
        for(int i = 1; i <= c; i++)
           {
               if(i % a == 0 && i % b == 0)
                   cout << " FB ";
               else if(i % a == 0)
                   cout << " F ";
               else if(i % b == 0 )
                   cout << " B ";
               else
                   cout << i << " ";
           }
           cout << "\n";



    }
    return 0;
}
> I did a sample run and it runs fine.
No, it doesn't. You've got a lot of whitespace
1 2  F 4  B  F 7 8  F  B 
1 2 F 4 B F 7 8 F B



Also while( file>>a>>b>>c )
Last edited on
cool got it. thank you.
Topic archived. No new replies allowed.