Help me on my assignment

I have this question for my assignment and i don't have any idea how to do

Question 1

"Allow the user to enter an integer, between 1 to 9 only. You may use the value ‘0’ to terminate the program. Then display the output as follows:

Sample Run 1
Enter an integer (1-9):4
1
121
12321
1234321


Sample Run 2
Enter an integer (1-9): 20
You have entered an invalid entry, please try again.

Enter an integer (1-9): 0
Thank you for using this program.


Your help is much appriciated

(Try to use remark to explain function and process area and try to use simple method for me im a progaming nooby =/)

TQVM
Last edited on
Have you covered recursive functions? ...or more to the point what have you covered so far which would deal with this and similar problems?

I dont think this is optimization code..Even i am beginner and this ll help u as of now

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include<iostream>
using namespace std;
int main()
{
 int i,j,l,k,n;

do
{
 cout<<"Enter the number";
 cin>>n;
if(n>9)
 exit(0);

 for(i=1;i<=n;i++)
 {
  for(l=n;l>i;l--)
  {
   cout<<" ";
  }
  for(j=1;j<=i;j++)
  {
    cout<<j;
  }

        for(k=i-1;k>0;k--)
        {
  cout<<k;
 }
 cout<<"\n";

}
}while(n!=0);
cout<<" Thank You";

}
TQ For the reply...And sry for the late reply =/

I did try your code vintho...and i do some edit on it for it to work like what the question want...btw im using DoSBox to do my assignment...

Any way i still have 3 more question to complete...

Question 2

There is an array of String type named arrFruits with the following values: pear, banana, apple, cherry, watermelon, papaya. Sort the contents using an appropriate sort routine and display the sorted data from the same array.


Question 3

Using two arrays, named arr_A and arr_B respectively, write a function named concantenate that join the values from arr_A to the values from arr_B according to their sequence and stores the concatenated values in arr_C. Display the contents of arr_A, arr_B and arr_C. The three arrays are declared as integer type.



Question 4

Randomly enters 10 alphabets into arr_A. Then allow the user to enter a value into a variable. The value of the variable is then compared with the values in arr_A. If there is a match, the program will display the subscript of the cell containing the target value. If more than one of the cells contains the target value, then the function should return all the subscripts that has the identical values with the variable.



Once again, your hlp is really really appreciated
Topic archived. No new replies allowed.