In: Computer Science
complete the program
#include <cstdlib>
#include <iostream>
#include <iomanip>
using namespace std;
int main(int argc, char** argv)
{
int number, sum, count;
// Write a while loop that reads a number from the user and
loop
// until the number is divisible by 7
cout << "What is the number? "; cin >> number; while (
... ) { ... }
cout << number << " is divisible by 7!! << endl
<< endl;
// Write a for loop that counts down from 10 to 0
// Write a for for loop that adds up all the numbers from 1 to
512
// Write a while loop that reads numbers from the user. Each number
must be
// between 0 and 100 (inclusive). The loop ends when the user
enters -99.
// Print the average of all the numbers. sum = count = 0;
cout << "Enter number between 0 and 100: "; cin >>
number;
while ( ... ) { if (number ... || number ... )
cout << "Not in the range. Skipping" << endl;
else { // count the number of entries and the total sum. ...
}
cout << "Enter number between 0 and 100: "; cin >>
number;
}
cout << "The average is:" << fixed <<
setprecision(2) << float(sum) / count << endl; return
0;
#include <cstdlib>
#include <iostream>
#include <iomanip>
using namespace std;
int main(int argc, char** argv)
{
int number, sum, count;
// Write a while loop that reads a number from the user and
loop
// until the number is divisible by 7
cout << "What is the number? "; cin >> number; while (
number%7!=0 ) { cout << "What is the number? "; cin >>
number; }
cout << number <<" is divisible by 7!!
"<<endl;
// Write a for loop that counts down from 10 to 0
count=0;
//counting from 10 down to 0
for(int i=10;0<=i;i--)
{
cout<<i<<endl;//prints i value, remove it ,if you don't
need it
count+=1;
}cout<<"The count of numbers 10 down to 0
is:"<<count<<endl;
// Write a for for loop that adds up all the numbers from 1 to
512
sum=0;
for(int i=1;i<=512;i++)
sum+=i;//adding to sum
cout<<"The sum of values from 1 to
512:"<<sum<<endl;
// Write a while loop that reads numbers from the user. Each number
must be
// between 0 and 100 (inclusive). The loop ends when the user
enters -99.
// Print the average of all the numbers. sum = count = 0;
sum=count=0;
cout << "Enter number between 0 and 100: "; cin >>
number;
while ( number!=-99 ) { if (number <0 || 100<number )
{
cout << "Not in the range. Skipping" << endl;
}
else
{
sum+=number;
count+=1;}
cout << "Enter number between 0 and 100: "; cin >>
number;
}
cout << "The average is:" << fixed <<
setprecision(2) << float(sum) / count << endl;
return 0;
}
output:
What is the number? 1
What is the number? 10
What is the number? 14
14 is divisible by 7!!
10
9
8
7
6
5
4
3
2
1
0
The count of numbers 10 down to 0 is:11
The sum of values from 1 to 512:131328
Enter number between 0 and 100: 200
Not in the range. Skipping
Enter number between 0 and 100: -10
Not in the range. Skipping
Enter number between 0 and 100: 10
Enter number between 0 and 100: 20
Enter number between 0 and 100: 30
Enter number between 0 and 100: -99
The average is:20.00
Process exited normally.
Press any key to continue . . .