Write a C program that reads in 50 whole numbers from an inp


Write a C++ program that reads in 50
whole numbers from an inputdata file named numbers.txt.
The program should determine and print to the screen how many of the numbers were even and how many were odd and the percent that were even and the percent that were odd. The program should use a count-control while loop to read in and process the numbers.

Solution

#include <iostream>
#include <fstream>
using namespace std;


int main()
{
    ifstream infile(\"numbers.txt\"); //
    int even=0;
    int odd=0;
    int i=0;
    while(i<50)
    {
        int number;
        infile>>number;
        if(number%2==0)
            even++;
        else
            odd++;
        i++;
   }
  
   cout<<endl<<\"Total number of Even numbers \"<< even<<\" and its percentage \"<<(even/50)*100;
   cout<<endl<<\"Total number of Odd numbers \"<< odd<<\" and its percentage \"<<(odd/50)*100;
}

 Write a C++ program that reads in 50 whole numbers from an inputdata file named numbers.txt. The program should determine and print to the screen how many of t

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site