Task - In a cycle with a precondition, numbers are entered by the user until their sum exceeds 100. Determine the number of even and odd numbers entered

#include stdio.h #include conio.h #include math.h #include Windows.h #include iostream using namespace std; void main() { SetConsoleCP(1251); SetConsoleOutputCP(1251); float x, kn, kc, summa; summa = 0; kc = 0; kn = 0; do { printf("%s", "Vvedite chislo x: "); scanf("%f", &x); summa = x + summa; } while (summa < 100); if (x % 10 % 20 == 0) ++kc; else ++kn; x /= 10; } cout << "Kol-vo 4etnix cifr:" << kc < endl << "Kol-vo ne4etnix cift:" << kn << endl; } 

Closed due to the fact that the essence of the question is not clear to the participants Visman , Vladimir Martyanov , αλεχολυτ , tutankhamun , Kromster 4 Apr '17 at 4:21 .

Try to write more detailed questions. To get an answer, explain what exactly you see the problem, how to reproduce it, what you want to get as a result, etc. Give an example that clearly demonstrates the problem. If the question can be reformulated according to the rules set out in the certificate , edit it .

  • 2
    And where is the PRE condition? - Akina
  • one
    Well, let's start at least from the fact that you do not have a cycle with a pre- condition in the program ... - D-side
  • 2
    So numbers or numbers ? And yet - why do you need games with ConsoleCP when working with Latin letters? :) - Harry
  • Help precondition write - Volka
  • one
    The precondition is organized using WHILE () {}. While DO {} WHILE () works on a post-condition. - Akina

1 answer 1

 int main() { unsigned int x, sum = 0; unsigned int even_n = 0, even_d = 0, odd_n = 0, odd_d = 0; while(sum <= 100) { cout << "Enter integer number: "; cin >> x; sum += x; if (x%2) odd_n++; else even_n++; while(x) { if (x%2) odd_d++; else even_d++; x /= 10; } } cout << "Even numbers: " << even_n << endl; cout << "Odd numbers: " << odd_n << endl; cout << "Even digits: " << even_d << endl; cout << "Odd digits: " << odd_d << endl; } 
  • Thank you very much - Volka
  • Well, if the answer is arranged - mark as accepted, and deal with the end ... - Harry
  • and another question, what does even_d and odd_d mean - Volka
  • Even and odd numbers . You have not explained, you need a number of numbers or numbers ... - Harry
  • Already the second answer is @Harry with a solution to the problem I stumble upon. - Ilya Chizhanov