By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,750 Members | 1,187 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,750 IT Pros & Developers. It's quick & easy.

same class project need help

P: 4
i was helped with my project but when i tried to compile it it kept showing me errors and wasn't able to figure it out.

The project is:

Write an original C++ program that will take as input a character and an integer.
If the integer is even, them add one to it.
The output will be a "diamond" composed of the character and as wide as the int.
Example:
Enter a character and an integer:
@ 5

@
@@@
@@@@@
@@@
@

Enter a character and an integer:
$ 6

$
$$$
$$$$$
$$$$$$$
$$$$$
$$$
$

couldn't make it a diamond shape but you get the point.i'll really appreciate it.
Oct 5 '06 #1
Share this Question
Share on Google+
3 Replies


P: 41
you need include some header files
i don't include here :D

Expand|Select|Wrap|Line Numbers
  1.  void main() 
  2. {
  3. cout<<"Input a character and a integer number:"<<endl;
  4. char ch;
  5.  
  6. int num;
  7.  
  8. cin>>ch>>num;
  9.  
  10. if(num<0)
  11.  
  12. num=1;
  13.  
  14. if(num%2==0)
  15.  
  16. num++;
  17.  
  18. system("cls");
  19.  
  20. for(int i=0; i<num; i++)
  21.  
  22. {
  23.  
  24. if(i<=num/2)
  25.  
  26. {
  27.  
  28. for(int j=0; j<(i*2+1); j++)
  29.  
  30. {
  31.  
  32. cout<<ch;
  33.  
  34. }
  35.  
  36. }
  37.  
  38. else
  39.  
  40. {
  41.  
  42. for(int j=0; j<((num-1-i)*2+1); j++)
  43.  
  44. {
  45.  
  46. cout<<ch;
  47.  
  48. }
  49.  
  50. }
  51.  
  52. cout<<endl;
  53.  
  54. }
  55. }
  56.  
Oct 5 '06 #2

100+
P: 293
D_C
You should have kept this with the other thread. I gave you some code, but not all of it. I left some comments where you need to fill in the blanks. Post the code, and we'll tell you why it doesn't compile, and what you have to do to fix it.
Oct 5 '06 #3

10K+
P: 13,264
You should have kept this with the other thread. I gave you some code, but not all of it. I left some comments where you need to fill in the blanks. Post the code, and we'll tell you why it doesn't compile, and what you have to do to fix it.
Or better still try to understand the code you were given.Consult some texts if you have to.
Oct 5 '06 #4

Post your reply

Sign in to post your reply or Sign up for a free account.