Banners

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ambanks04
    New Member
    • Mar 2008
    • 8

    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"<<e ndl;
    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;c ounter!=(any+1)/2;counter++){
    for(count=space s;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;cou nter--){
    for(count=0;cou nt!=spaces;coun t++)
    cout<<" ";
    spaces++;
    for(count=size; count>0;count--)
    cout<<"*";
    size-=2;
    cout<<endl;
    }

    system ("PAUSE");

    }
  • fual
    New Member
    • Feb 2008
    • 28

    #2
    [CODE=cpp]
    //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"<<e ndl;
    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;c ounter!=(any+1)/2;counter++){
    for(count=space s;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;cou nter--){
    for(count=0;cou nt!=spaces;coun t++)
    cout<<" ";
    spaces++;
    for(count=size; count>0;count--)
    cout<<"*";
    size-=2;
    cout<<endl;
    }

    system ("PAUSE");

    }[/CODE]
    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;
    [CODE=cpp]size=any-2;
    spaces+=2;
    for(counter=any/2;counter>0;cou nter--){
    for(count=0;cou nt!=spaces;coun t++)
    cout<<" ";
    spaces++;
    for(count=size; count>0;count--)
    cout<<"*";
    size-=2;
    cout<<endl;
    }

    system ("PAUSE");

    }[/CODE] Isn't part of any function

    Comment

    Working...