I have the following code so far, but it goes into an infinite loop when executed. Could someone please review the code? I'm not certain how to get the conditions in there to only print 2 to 8 clowns. Any suggestions?
/* Solo4.cpp. This program prompts the user to enter an integer, N,
between the values 2 to 8, then prints N number of clowns that
end with a base
*/
#include<iostream>
using namespace std;
void PrintInfo();
//Prints information about the program.
void PrintDirections() ;
//Prints directions for the user on how to use the program.
void MakeOneClown() ;
//Prompts user to enter a number, N, between 2 to 8, then prints
//N of clowns.
void MakeBase() ;
//Prints a base at the end of the stack of clowns.
int main()
{
int N; // number of clowns
PrintInfo() ;
PrintDirections () ;
int i;
for (int i = 1; i < N; i++)
{
MakeOneClown () ;
MakeBase() ;
}
}
/* ************************************************ */
/* PRINT INFORMATION */
/* ************************************************ */
/* Prints information about the program */
void PrintInfo()
{
cout << "This program uses ASCII art to make a stack of carnival clowns.";
cout << endl;
cout << "You may request a stack containing between 2 and 8 clowns.";
cout << endl;
}
cout << "This program uses ASCII art to make a stack of" << endl;
cout << "carnival clowns. You may request a stack containing"<< endl;
cout << "between 2 and 8 clowns." << endl;
cout << endl;
cout << "How many clowns would you like to see? ==>" <<endl;
cin >> N ;
}
N is not initialized to any value in main(). Instead of declaring it in PrintDirections(), pass it be reference.
The N in main() is NOT the N in PrintDirections().
Thank you for the quick reply! i'm not certain on what part of my code is falling short still. I took out N from printdirections and put it in int main(). It stopped the loop but now it won't print anything after an N is entered. This is what I have:
int main()
{
int N; // number of clowns
cout << endl ;
PrintInfo() ;
PrintDirections () ;
cout << "how many clowns would you like to see? ==>" << endl;
cin >> N ;
return N ;
int i;
for (int i=1; i < N; i++)
{
MakeOneClown();
MakeBase() ;
}
}
/* ************************************************ */
/* PRINT INFORMATION */
/* ************************************************ */
/* Prints information about the program */
void PrintInfo()
{
cout << "This program uses ASCII art to make a stack of carnival clowns.";
cout << endl;
cout << "You may request a stack containing between 2 and 8 clowns.";
cout << endl;
}
void PrintDirections()
{
cout << "This program uses ASCII art to make a stack of" << endl;
cout << "carnival clowns. You may request a stack containing" << endl;
cout << "between 2 and 8 clowns." << endl;
cout << endl;
}