c++ - I am encountering an error with my code for fizzbuzz -


#include <iostream> using namespace std;  int f[33] = {3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33, 36, 39, 42, 45, 48, 51, 54, 57, 60, 63, 66, 69, 72, 75, 78, 81, 84, 87, 90, 93, 96, 99};  int b[20] = {5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95, 100};   int main (){  (int x=100; x >= 1; x-- ){   if (x == f){     cout << "fizz" << endl; }else{     if(x ==b){         cout << "buzz" << endl;     }else{         if(x==f & x==b){             cout << "fizzbuzz" << endl;          }else{             cout << x << endl;         }     } }  } } 

i still learning, may not best way solve problem. want know wahts wrong code. thanks

x int, while f array. cannot compare them way:

if (x == f){ 

if technique check whether x in array f, suggest, have check each value in f,

 if(x == f[i++]){ 

where i index used traverse f array.

also, might consider evaluating condition of x in both f , b before individual evaluation.


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -