Member Avatar for asdsadddsadsd

Hi how can i arrange these numbers in acending and descending order?

include <iostream.h>
include <conio.h>
main(){



   int n1=0;
   int n2=0;
   int n3=0;
   int n4=0;
   int n5=0;
   int n6=0;
   int n7=0;
   int n8=0;
   int n9=0;
   int n10=0;
   int sum=0;
   float ave = 0.0;
   int highest;
   int smallest;
   float mean = 0.0;
   int evenCount = 0;
   int oddCount = 0;

          cout<<"\n\n\tEnter ten numbers";
   cout<<"\n\tFirst number:";
                    cin>>n1;
   cout<<"\n\tSecond number:";
                    cin>>n2;
   cout<<"\n\tThird number:";
                    cin>>n3;
   cout<<"\n\tFourth number:";
                    cin>>n4;
   cout<<"\n\tFifth number:";
                    cin>>n5;
   cout<<"\n\tSixth number:";
                    cin>>n6;
   cout<<"\n\tSeventh number:";
                    cin>>n7;
   cout<<"\n\tEighth number:";
                    cin>>n8;
   cout<<"\n\tNinth number:";
                    cin>>n9;
   cout<<"\n\tTenth number:";
                    cin>>n10;

//Getting the sum of all numbers.

       sum = n1+n2+n3+n4+n5+n6+n7+n8+n9+n10;

//Getting the average of all numbers.
ave = sum/10.0;

//Getting the highest number.

   if(n1>n2 && n1>n3 && n1>n4 && n1>n5 && n1>n6 && n1>n7 && n1>n8 && n1>n9 && n1>n10)
                     {highest=n1;
                     }
   if (n2>n1 && n2>n3 && n2>n4 && n2>n5 && n2>n6 && n2>n7 && n2>n8 && n2>n9 && n2>n10)
                {highest=n2;
                }
   if (n3>n1 && n3>n2 && n3>n4 && n3>n5 && n3>n6 && n3>n7 && n3>n8 && n3>n9 && n3>n10)
                {highest=n3;
                }
   if (n4>n1 && n4>n2 && n4>n3 && n4>n5 && n4>n6 && n4>n7 && n4>n8 && n4>n9 && n4>n10)
                {highest=n4;
                }
   if (n5>n1 && n5>n2 && n5>n3 && n5>n4 && n5>n6 && n5>n7 && n5>n8 && n5>n9 && n5>n10)
                {highest=n5;
                 }
   if (n6>n1 && n6>n2 && n6>n3 && n6>n4 && n6>n5 && n6>n7 && n6>n8 && n6>n9 && n6>n10)
                {highest=n6;
                }
   if (n7>n1 && n7>n2 && n7>n3 && n7>n4 && n7>n5 && n7>n6 && n7>n8 && n7>n9 && n7>n10)
                {highest=n7;
                }
   if (n8>n1 && n8>n2 && n8>n3 && n8>n4 && n8>n5 && n8>n6 && n8>n7 && n8>n9 && n8>n10)
                {highest=n8;
                }
   if (n9>n1 && n9>n2 && n9>n3 && n9>n4 && n9>n5 && n9>n6 && n9>n7 && n9>n8 && n9>n10)
                {highest=n9;
                }
   if (n10>n1 && n10>n2 && n10>n3 && n10>n4 && n10>n5 && n10>n6 && n10>n7 && n10>n8 && n10>n9)
                {highest=n10;
                }

//Getting the smallest number.

   if(n1<n2 && n1<n3 && n1<n4 && n1<n5 && n1<n6 && n1<n7 && n1<n8 && n1<n9 && n1<n10)
                     {smallest=n1;
                     }
   if (n2<n1 && n2<n3 && n2<n4 && n2<n5 && n2<n6 && n2<n7 && n2<n8 && n2<n9 && n2<n10)
                {smallest=n2;
                }
   if (n3<n1 && n3<n2 && n3<n4 && n3<n5 && n3<n6 && n3<n7 && n3<n8 && n3<n9 && n3<n10)
                {smallest=n3;
                }
   if (n4<n1 && n4<n2 && n4<n3 && n4<n5 && n4<n6 && n4<n7 && n4<n8 && n4<n9 && n4<n10)
                {smallest=n4;
                }
   if (n5<n1 && n5<n2 && n5<n3 && n5<n4 && n5<n6 && n5<n7 && n5<n8 && n5<n9 && n5<n10)
                {smallest=n5;
                 }
   if (n6<n1 && n6<n2 && n6<n3 && n6<n4 && n6<n5 && n6<n7 && n6<n8 && n6<n9 && n6<n10)
                {smallest=n6;
                }
   if (n7<n1 && n7<n2 && n7<n3 && n7<n4 && n7<n5 && n7<n6 && n7<n8 && n7<n9 && n7<n10)
                {smallest=n7;
                }
   if (n8<n1 && n8<n2 && n8<n3 && n8<n4 && n8<n5 && n8<n6 && n8<n7 && n8<n9 && n8<n10)
                {smallest=n8;
                }
   if (n9<n1 && n9<n2 && n9<n3 && n9<n4 && n9<n5 && n9<n6 && n9<n7 && n9<n8 && n9<n10)
                {smallest=n9;
                }
   if (n10<n1 && n10<n2 && n10<n3 && n10<n4 && n10<n5 && n10<n6 && n10<n7 && n10<n8 && n10<n9)
                {smallest=n10;
                }

//Getting the count of even and odd numbers.

   if (n1 != 0 && n1 % 2 == 0)
                {evenCount++;}
     else{oddCount++;}

   if (n2 != 0 && n2 % 2 == 0)
                {evenCount++;}
     else{oddCount++;}

   if (n3 != 0 && n3 % 2 == 0)
                {evenCount++;}
     else{oddCount++;}

   if (n4 != 0 && n4 % 2 == 0)
                {evenCount++;}
     else{oddCount++;}

   if (n5 != 0 && n5 % 2 == 0)
                {evenCount++;}
     else{oddCount++;}

   if (n6 != 0 && n6 % 2 == 0)
                {evenCount++;}
     else{oddCount++;}

   if (n7 != 0 && n7 % 2 == 0)
                {evenCount++;}
     else{oddCount++;}

   if (n8 != 0 && n8 % 2 == 0)
                {evenCount++;}
     else{oddCount++;}        

   if (n9 != 0 && n9 % 2 == 0)
                {evenCount++;}
     else{oddCount++;}

   if (n10 != 0 && n10 % 2 == 0)
                {evenCount++;}
     else{oddCount++;} 

//Getting the mean of the highest and smallest number.

   mean=(highest+smallest)/2;


 cout<<"\n\n\tc) Highest: ";cout<<highest;
 cout<<"\n\n\td) Smallest: ";cout<<smallest;
 cout<<"\n\n\te) Sum: ";cout<<sum;
 cout<<"\n\n\tf) Average: ";cout<<ave;  
 cout<<"\n\n\tg) How many even numbers: ";cout<<evenCount;
 cout<<"\n\n\th) How many odd numbers: ";cout<<oddCount;
 cout<<"\n\n\ti) Mean: ";cout<<mean;  
   getch();
   }

Recommended Answers

All 4 Replies

Have you thought about using an array?

Arrays

Member Avatar for asdsadddsadsd

Our teacher made us use if statements only so i guess i won't be using those..

If you're only allowed to use if statements, what is the meaning of arrange these numbers? You have no way to move them around into an order, because they're not contained in anything, so when you say "arrange" what do you mean?

How do you know you can't use an array? Were you explicitly told to use only an if statement? I note that you're using int, else, <, ++, % and lots and lots of other things. They're not if statements, so how come you're using them? If you're allowed to use them, what else are you allowed to use?

First of all, have you been taugth arrays? and have you asked if you can use them?

If you definetily are not suppouse to use arrays, then technically you wont be able to sort them as they will not be in a place where you can access them sequencially. The most you can do is print them on the order you want to. Here is a hint on how you could approach it: The highest number has 0 numbers that are higher than it, the next one down has only 1 higher number than it, the next one has 2 higher numbers than it..... and so on. If you can put that into a function, it will save you a lot of typing. Regardless, it will be a lot of if statememnts

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.