I need to write a program that asks the user to enter any integer value. The program will store only the numbers that are divisible by 7 or divisible by 3 in an array. The program should declare a size of 10- if the number enter by the user is divisible by 3 or 7, then store it in the array-i need to allow the user to enter as many numbers as desired or until the array is full- Once the user completes the array size my program should First: display all the numbers in the array that are divisible by 3, their sum, and their average. (Hint: use a for loop that only displays and processes an array element only if ((data[i] %3) == 0) ) assuming the array’s name is data and the array’s subscript is i.)
b. Second: display all the numbers in the array that are divisible by 7, their sum, and their average. (Hint: use a for loop that only displays and processes an array element only if ((data[i] %7) == 0) ) assuming the array’s name is data and the array’s subscript is i.)
c. Third: display the sum and average of all numbers as well as the maximum and minimum.
I need to write a program that asks the user to enter any integer value.
When asking for help, you should also provide your efforts to solve whatever problem you're having. Nobody can help you with the code you aren't showing.
#include <iostream>
int main ()
{
int hw[10] = {0};
int value = 0;
int counter = 0;
std::cout << "Please enter 10 numbers that are divisible by 3 and/or 7\n";
do
{
std::cin >> value;
if (value % 3 == 0 or value % 7 == 0)
{
std::cout <<"This is valid number " << counter + 1 << " of 10\n";
hw[counter] = value;
counter++;
}
else
std::cout << "Invalid number try another\n";
} while (counter < 10);
std::cout << "All 10 numbers entered\n";
return 0;
}
I wanted to improve my program and shorten the amount written inside the main. My math is wrong and the program is crashing at the end when its calculating the average of the input. My intentions were to average the inputs by the number of inputs like if all 3's were type then divide it by 10 to get 3. I getting 13 instead of 30( typing 3 ten times).
#include <iostream>
using namespace std;
/* This program will asked the user to enter 10 numbers
that divisible by 3 and 7 */
void message1 ( )
{
cout << " Hello, Welcome my last program of 2016!"<< endl;
cout << "****************************************";
}
void message ( )
{
cout << "\n\t\tThank you for using this program"<< endl;
cout << " Happy Holidays";
}
int SUM,sum,count;
void Aaverage ( int SUM, int sum)
{
cout << "\n\t The complete average is; " << (SUM + sum)/count <<endl ;
cout << "\t____________________\n";
}
void sumA( int firstNo, int secondNO)
{
cout <<"\n\t The complete sum is; " << SUM + sum << endl;
cout <<"\t_____________________";
}
int main ()
{
message1();
int A,B,array[10], num=0,counter=0;
float A3=0, A7=0, SUM=0,sum=0;
int min=0,max=0;
cout <<" \n\n\n\n\nPlease enter 10 numbers that are divisible by 3 and 7\n\n ";
do
{
cin >> num;
if (num%3==0 || num%7==0)
{
cout <<"\n This is a valid number " << counter+2 << " of 10\n";
array [10]=num;
counter++;
}
else
cout <<"\nThis is not a valid number";
}
while (counter< 10);
int count=0;
for (int i=0;i<10;i++)
{
if (num%3==0)
{
count++;
cout <<"\nNumbers divisible by 3= "<< num%3;
cout << "\n\n";
SUM= count + num;
A3 =num/count;
}
}
count=0;
for ( int i=0;i<10; i++)
{
if (num%7 ==0)
{
count ++;
cout <<"\nNumbers are divisible by 7= " << num;
cout << "\n\t\t\t\t";
sum= num + count;
A7= num/count;
}
}
max=array[10];
for (int num=1;num<10;num++)
if (array[10]>max)
max=array[10];
min=array[10];
for (int num=1; num<10;num++)
if (array[10]<min)
min=array[10];
cout << "\nSum for 3= " << SUM;
cout << "\nAverage for 3= " << A3;
cout << "\nAvegage for 7 = "<<sum;
cout << "\nSum for 7= " << A7;
cout << "\nThe Maximum is= " << max;
cout << "\nThe Minimun is = " << min;
#include <iostream>
#include <limits>
int main ()
{
int hw[10] = {0};
int value = 0;
int counter = 0;
int counter_3 = 0;
int counter_7 = 0;
int sum = 0;
int sum_3 = 0;
int sum_7 = 0;
int max = std::numeric_limits<int>::min();
int min = std::numeric_limits<int>::max();
std::cout << "Please enter 10 numbers that are divisible by 3 and/or 7\n";
do
{
std::cin >> value;
if (value % 3 == 0 or value % 7 == 0)
{
std::cout <<"This is valid number " << counter + 1 << " of 10\n";
hw[counter] = value;
sum += value;
if (value < min ) min = value;
if (value > max) max = value;
if(value % 3 == 0)
{
sum_3 += value;
counter_3++;
}
if(value % 7 == 0)
{
sum_7 += value;
counter_7++;
}
counter++;
}
else
std::cout << "Invalid number try another\n";
} while (counter < 10);
std::cout << "All 10 numbers entered.\n";
std::cout << " Total of all numbers: " << sum << '\n';
std::cout << " Average of all numbers: " << sum/(double)counter << '\n';
std::cout << " Minimum of all numbers: " << min << '\n';
std::cout << " Maximum of all numbers: " << max << '\n';
if(counter_3 > 0)
{
std::cout << " Total of all numbers divisible by 3: " << sum_3 << '\n';
std::cout << "Average of all numbers divisible by 3: " << sum_3/((double)counter_3) << '\n';
}
else
std::cout << "No numbers were divisible by 3.\n";
if(counter_7 > 0)
{
std::cout << " Total of all numbers divisible by 7: " << sum_7 << '\n';
std::cout << "Average of all numbers divisible by 7: " << sum_7/((double)counter_7) << '\n';
}
else
std::cout << "No numbers were divisible by 7.\n";
return 0;
}