Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Problem: 1) read an unknown number of positive integers, but 50 or less Use a fu

ID: 3635699 • Letter: P

Question

Problem:
1) read an unknown number of positive integers, but 50 or less
Use a function called last_statement to print out the final statement.
This function uses a switch statement to print out how many integers there are, by
“tens”. For instance, if there are less than 10 integers, it prints out “The number
of numbers read was in the single digits”. If there are between 10 and 19 integers
(inclusive), it prints out “The number of numbers read was in the tens”. If there
are between 20 and 29 integers, it prints out “The number of numbers read was in
the twenties”, etc.

SAMPLE INPUT: 100 49 -26 64 16

SAMPLE OUTPUT:
The number of numbers read was in the single digits

Note: The output has 4 integers because -26 is invalid, and so the output is the phrase above.

Explanation / Answer

Please Rate:Thanks

#include<iostream.h>
void main()
{
int a[50];
int len=0;
cout<<"Enter integers or 0 to exit";
for(int i=0;i<50;i++)
{
cin>>a[i];
if(a[i]==0)
break;
else if(a[i]<0)
len--;
else
len++;
}
void last_statement(int);
last_statement(len+1);
}
void last_statement(int len){
int a=0;
if(len<10)
a=1;
else if(len>=10 && len<=19)
a=2;
else if(len>=20 && len<=29)
a=3;
else if(len>=30 && len<=39)
a=4;
else if(len>=40 && len<=49)
a=5;
else if(len>=50 && len<=59)
a=6;
else if(len>=60 && len<=69)
a=7;
else if(len>=70 && len<=79)
a=8;
else if(len>=80 && len<=89)
a=9;
else if(len>=90 && len<=99)
a=10;
switch(a)
{
case 1: cout<<"The number of numbers read was in the single digits";break;
case 2: cout<<"The number of numbers read was in the tens";break;
case 3: cout<<"The number of numbers read was in the twenties";break;
case 4: cout<<"The number of numbers read was in the thirties";break;
case 5: cout<<"The number of numbers read was in the fourties";break;
case 6: cout<<"The number of numbers read was in the fifties";break;
case 7: cout<<"The number of numbers read was in the sixties";break;
case 8: cout<<"The number of numbers read was in the seventies";break;
case 9: cout<<"The number of numbers read was in the eighties";break;
case 10: cout<<"The number of numbers read was in the nineties";break;
default:cout<<"The number of numbers read was in more than hundreds ";
}
cout<<" Total number of digits "<<len;
}

--------------------------------------

Output:


Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote