c++ - Possible operations error, random single digit output -


i have written program class asks positive number , based on number, calculations performed. had great stack folks last week asked professor re-write , simplify code. have done , math not coming out right. have run debugger dont see values being passed incorrect. also, numbers failing "if (number > 0)" test.

could compile error though successful build message?

thanks in advance!

here code.

#include <iostream> #include <string> #include <fstream>   #include <iomanip> #include <stdexcept> #include <cstdlib>  using namespace std;  int main () {     system ("color f0");      int number, countif = 0, countwhile = 0, countdo = -1, h = 0, = 0, x = 0, y = 0;     char repeat = 'y';      {          cout << "please enter positive integer or 0 quit: ";         cin >> number;         x = number, y = number;         cin.ignore();          if (number < 0)              cout << "error: integer entered either not positive or zero.\n" << endl;          else if (number > 0)         {             if (number%2 == 0 && number%5 == 0)                 (y%5; countif <= y; countif +=5)                     {                         = y / 10;                         += countif;                         cout << countif << " ";                     }              else if                  (countwhile < x && number%2 == 0)                      {                         countwhile += 2;                         cout << countwhile << " ";                     }              else                  {                     countdo +=2;                     cout << countdo << " ";                 }         }               cout << "\n\ndo wish continue? (y or n): ";             cin >> repeat; }         while (number != 0 && repeat == 'y' || repeat == 'y');        //cout << "\nthanks playing!" << endl;     system ("pause");     return 0;   } 

output should similar to:

enter image description here

what getting is:

enter image description here

i modified code this:

        else if             (countwhile < x && number%2 == 0)                 {                     for(countwhile+=2; countwhile<x; countwhile+=2)                         cout << countwhile << " ";                 }          else             {                     for(countdo+=2; countdo<x; countdo+=2)                         cout << countdo << " ";             } 

and output like:

please enter positive integer or 0 quit: 82 2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50 52 54 56 58 60 62 64 66 68 70 72 74 76 78 80  wish continue? (y or n): y please enter positive integer or 0 quit: 75 1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 41 43 45 47 49 51 53 55 57 59 61 63 65 67 69 71 73 

hope helps.


Comments

Popular posts from this blog

android - getbluetoothservice() called with no bluetoothmanagercallback -

sql - ASP.NET SqlDataSource, like on SelectCommand -

ios - Undefined symbols for architecture armv7: "_OBJC_CLASS_$_SSZipArchive" -