Question: KINDLY CHECK THE PROBLEMS WITH MY CODE I see problems with the output. My inputs: 1 2 3 4 5 THE OUTPUT #7(the lowest number)
I see problems with the output.
My inputs:
1
2
3
4
5
THE OUTPUT
#7(the lowest number)
Smallest number = 2
WHICH SHOULD BE:
Smallest number = 1
#8(display all numbers)
Display All Numbers = 2 2 3 4 5
WHICH SHOULD BE:
Display All Numbers = 1 2 3 4 5
THE CODE:
//Single array - A group of consecutive memory locations of the same name and type, structures of related data items.
//Array index always starts with one.
// Single array with function
#include
using namespace std;
// Function Name
//all unimplemented methods
int sumAll(int num[5]);
int SumEvenSS(int num[5]);
int SumEven(int num[5]);
int ProOddSS(int num[5]);
int ProOdd(int num[5]);
void High (int num[5]);
void Low (int num[5]);
void display(int num[5]);
int x, sum=0, choice;
int num[5];
int main()
{
for(x=0; x<=4; x++)
{ cout<<("Enter a number: ");
cin>>num[x];
}
cout<<" CHOICES: ";
cout<<" 1. The sum of all numbers ";
cout<<" 2. The sum of even subscripts";
cout<<" 3. The sum of even numbers ";
cout<<" 4. The product of odd subscripts ";
cout<<" 5. The product of odd numbers ";
cout<<" 6. The highest number ";
cout<<" 7. The lowest number ";
cout<<" 8. Display all numbers ";
do{
cout<<(" Enter your choice[1-8]: ");
cin>>choice;
switch(choice){//switch case for choice the menu
case 1:cout<< "Display the sum of all numbers";
sum= sumAll(num);
cout<<" The sum is "<
break;
case 2:cout<< "Display the sum of numbers in even subscripts";
sum=0;
for(x=0; x<=4; x=x+2)
{ sum = sum +num[x]; }
cout<<" The sum is "<
break;
case 3:cout<< "Display the sum of even numbers";
sum=0;
for(x=0; x<=4; x++)
{if (num[x] % 2==0)
{
sum = sum +num[x];
} // if
}//for loop
cout<<" The sum is "<
break;
case 4:cout<<"Display the product of odd subscripts";
sum=ProOddSS(num);
cout<<" The sum is "<
break;
case 5:cout<<"Display the products of odd number";
sum=ProOdd(num);
cout<<" The product is "<
break;
case 6:cout<<"Display the Highest Number";
High(num);
break;
case 7:cout<<"Display the Lowest Number";
Low(num);
break;
case 8:cout<<"Display all numbers ";
display (num);
break;
default : cout<<" You entered an Invalid Number ";
} //switch
} while (choice<=8);
} // end of main
//START OF FUNCTION
int sumAll(int num[5]) //method for Sum all number
{ sum=0;
for(x=0; x<=4; x++)
{ sum = sum +num[x]; }
return sum;
}
int SumEvenSS(int num[5]){//methods for sum even subscripts
sum=0;
for(x=0;x<=4;x+=2){
sum=sum+num[x];
}
return sum;
}
void display(int num[5]) // methods for display all numbers
{
for(x=0; x<=4; x++)
{ cout<
}
int SumEven(int num [5]){//methods for sum of even numbers
sum=0;
for(x=0;x<=4;x++){
if(num[x]%2==0){
sum=sum+num[x];
}
}
return sum;
}
int ProOddSS(int num[5]){//methods for product of odd subscripts
sum=1;
for(x=0;x<=5;x+=3){
sum= sum * num[x];
}
return sum;
}
int ProOdd(int num[5]){//methods for product of odd numbers
sum=1;
for(x=0;x<=4;x++){
if(num[x]%2!=0){
sum=sum*num[x];
}
}
return sum;
}
void High(int num[5]){//methods for print high value
for(x=0;x<=4;++x)
{
if(num[0]<=num[x])
num[0]=num[x];
}
cout<<" Largest Number = " <
}
void Low(int num[5]){//methods for print low value
for(x=0;x<=4;x++)
{
if(num[0]>=num[x])
num[0]=num[x];
}
cout<<" Smallest Number = " <
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
