468,512 Members | 1,375 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,512 developers. It's quick & easy.

Banners

I have to do two exercises out of my textbook which work fine but I have to display a banner before doing the exercises
//March 19, 2008
//Exercise 5.23 and 5.24
//Project 1



#include <iostream>
using std::cout;
using std::endl;
using std::cin;

int main()
{
cout<<"Project 1"<<endl;
cout<<"name"<<endl;
cout<<"March 19, 2008"<<endl;
cout<<"Computer Science 111-003"<<endl;
cout<<"Exercise 5.23 and 5.24"<<endl;
cout<<endl;








void print (int any);


int any;
do{
cout<<"Please type in a positive odd integer: ";
cin>>any;
while((any%2==0)||(any<=0));
print(any);
return (0);
}
void print(int any)
{
int spaces=any/1, size=1, counter, count;
for(counter=0;counter!=(any+1)/2;counter++){
for(count=spaces;count>0;count--)
cout<<" ";
spaces--;
for(count=size;count>0;count--)
cout<<"*";
size+=2;
cout<<endl;
}
size=any-2;
spaces+=2;
for(counter=any/2;counter>0;counter--){
for(count=0;count!=spaces;count++)
cout<<" ";
spaces++;
for(count=size;count>0;count--)
cout<<"*";
size-=2;
cout<<endl;
}

system ("PAUSE");

}
Mar 17 '08 #1
1 5205
fual
28
Expand|Select|Wrap|Line Numbers
  1. //March 19, 2008
  2. //Exercise 5.23 and 5.24
  3. //Project 1
  4.  
  5.  
  6.  
  7. #include <iostream>
  8. using std::cout;
  9. using std::endl;
  10. using std::cin;
  11.  
  12. int main()
  13. {
  14. cout<<"Project 1"<<endl;
  15. cout<<"name"<<endl;
  16. cout<<"March 19, 2008"<<endl;
  17. cout<<"Computer Science 111-003"<<endl;
  18. cout<<"Exercise 5.23 and 5.24"<<endl;
  19. cout<<endl;
  20.  
  21.  
  22.  
  23.  
  24.  
  25.  
  26.  
  27.  
  28. void print (int any);
  29.  
  30.  
  31.     int any;
  32.     do{
  33.         cout<<"Please type in a positive odd integer: ";
  34.         cin>>any;
  35.     while((any%2==0)||(any<=0));
  36.     print(any);
  37.     return (0);
  38. }
  39. void print(int any)
  40. {
  41.     int spaces=any/1, size=1, counter, count;
  42.     for(counter=0;counter!=(any+1)/2;counter++){
  43.         for(count=spaces;count>0;count--)
  44.             cout<<" ";
  45.         spaces--;
  46.         for(count=size;count>0;count--)
  47.             cout<<"*";
  48.         size+=2;
  49.         cout<<endl;
  50. }
  51. size=any-2;
  52. spaces+=2;
  53. for(counter=any/2;counter>0;counter--){
  54.     for(count=0;count!=spaces;count++)
  55.         cout<<" ";
  56.     spaces++;
  57.     for(count=size;count>0;count--)
  58.         cout<<"*";
  59.     size-=2;
  60.     cout<<endl;
  61.     }
  62.  
  63. system ("PAUSE");
  64.  
  65. }
To start with you can't define a function within a function. Try pulling this outside the main function, that might give you an ide of where the problems with your code are.

Until you really know what you are doing always wrap if statements and for / while loops in '{}' brackets; although you don't need them they make it harder for you to make mistakes and the make it easier for other people to read you code. In your case I'm not really sure where one function is supposed to start and the other end, for example;
Expand|Select|Wrap|Line Numbers
  1. size=any-2;
  2. spaces+=2;
  3. for(counter=any/2;counter>0;counter--){
  4.     for(count=0;count!=spaces;count++)
  5.         cout<<" ";
  6.     spaces++;
  7.     for(count=size;count>0;count--)
  8.         cout<<"*";
  9.     size-=2;
  10.     cout<<endl;
  11.     }
  12.  
  13. system ("PAUSE");
  14.  
  15. }
Isn't part of any function
Mar 17 '08 #2

Post your reply

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

Similar topics

1 post views Thread by FS | last post: by
reply views Thread by Ron Lounsbury | last post: by
reply views Thread by Andy Dingley | last post: by
1 post views Thread by Terry Haufler | last post: by
reply views Thread by NPC403 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.