429,384 Members | 927 Online
Need help? Post your question and get tips & solutions from a community of 429,384 IT Pros & Developers. It's quick & easy.

# i need urgent help pleaaaase

 P: 40 First off, I need to mention this: I am in a basic programing (c++) class. So please refraim from using methoods above basic functions. I am a student who has no idea on how to solve this problem: 1. Write a program that asks the user to enter an odd integer between 1 and 10 (both inclusive). If the integer value was 3, then print out the following pattern on screen. * *** * If the value was 5, then the pattern printed is as follows: * *** ***** *** * *Note: the stars are in a diamond shape... website wont let me do spacing... And so on for other odd values less than 10. Use nested control statements in your program to get the desired output. If it wasn't for the last sentence, i'd do a bunch of if then statements, but that methood isn't allowed... any idea? i been at this for the past 12 hours now... -------------------------------------------------------------------------------- Sep 21 '06 #1
6 Replies

 P: 62 First off, I need to mention this: I am in a basic programing (c++) class. So please refraim from using methoods above basic functions. I am a student who has no idea on how to solve this problem: 1. Write a program that asks the user to enter an odd integer between 1 and 10 (both inclusive). If the integer value was 3, then print out the following pattern on screen. * *** * If the value was 5, then the pattern printed is as follows: * *** ***** *** * *Note: the stars are in a diamond shape... website wont let me do spacing... And so on for other odd values less than 10. Use nested control statements in your program to get the desired output. If it wasn't for the last sentence, i'd do a bunch of if then statements, but that methood isn't allowed... any idea? i been at this for the past 12 hours now... -------------------------------------------------------------------------------- To solve this you dont need methods just use simple for loop, generate the required logic from the for loops, the steps u should consider are the total no of rows is equal to number u entered and middle row is having number of stars same as the number u entered and in the above & below of that rows the number of stars decreases by odd value, use this logic in for loop Sep 21 '06 #2

 P: 40 To solve this you dont need methods just use simple for loop, generate the required logic from the for loops, the steps u should consider are the total no of rows is equal to number u entered and middle row is having number of stars same as the number u entered and in the above & below of that rows the number of stars decreases by odd value, use this logic in for loop thanks for the quick answer, I have come up with this code but Iknow that I am missing someting. also the prof gave us this hint ( if using double loop , you may need the modulus operator % ) so can you please tell me what is wrong in this code. thanks again Sep 21 '06 #3

 10K+ P: 13,264 thanks for the quick answer, I have come up with this code but Iknow that I am missing someting. also the prof gave us this hint ( if using double loop , you may need the modulus operator % ) so can you please tell me what is wrong in this code. thanks again Sorry, but where did you post the code? Sep 21 '06 #4

 P: 40 I AM SORRY , HERE IS THE CODE. Expand|Select|Wrap|Line Numbers  #include     using namespace std;   int main()   {   int height;   cout << "How tall is your diamond?" << endl;   cin >> height;   for (int i = 0; i <= height; i++) {   for (int j = 0; j <= i; j++)   {   cout << '*';   }   for ( int x=0; x >=i; x--)   {   cout << '*';   }   cout << endl;   }   return 0;   }   Sep 21 '06 #5

 P: 13 I hope that will help Expand|Select|Wrap|Line Numbers   #include    using    namespace std;   int main() {     int n;     int i, j, x;       cout << ": ";     cin >> n;       // you said this must be an odd number between 1 and 10, right ?     if ((n % 2) == 0 || n < 1 || n > 10) {         cerr << "bad number" << endl;         exit(1);     }       // only one '*', no diamond     if (n == 1) {         cout << "*" <<  endl;         return (0);     }       // increasing number of writen '*'     for (i = 1; i <= n; i += 2) {         x = (n - i) / 2; // number of spaces before '*' and after         for (j = 0; j < x; j++)             cout << " ";         for (j = 0; j < i; j++)             cout << "*";         for (j = 0; j < x; j++)             cout << " ";         cout << endl;     }       // decreasing     for (i = n - 2; i > 0; i -= 2) {         x = (n - i) / 2;         for (j = 0; j < x; j++)             cout << " ";         for (j = 0; j < i; j++)             cout << "*";         for (j = 0; j < x; j++)             cout << " ";         cout << endl;     }       return (0); }     sorry for any small typing error, it happends.. Sep 21 '06 #6

 P: 40 sin; you are the best. thanks a million. ayman723 Sep 23 '06 #7