#include <iostream> using namespace std; int getInput(void){ int s; do{ ; cout<<" Enter length between 0 and 64 (-1 to exit): "<<endl; cin>>s; cout<<" Length Entered: "<<s<<endl; } while( (s>-1)||(s<64)); return s; } void pritline(char A,char B,int n){ for(int i=1;i<=n;i++) if(i==1||i==n)cout<<A; else cout<<B; } void printStats(int N,int s){ cout<<N<<"squares are printed. Their average="<<(s/N)<<endl; } int main(){ int sum=0, N=0; while(1) { int p=getInput(); if(p=-1)break; sum+=p; N++; for(int i=1;i<=p;i++) if(i==1||i==p) void printline('+','+',p); else void printline('+','-',p); } void printStats(int N,int s); system("pause"); return 0; }

Here is my assingment, please somebody help me, I am so confused., why doesnt work

Re-write your Squares program so that it uses the following functions.

int getInput(void); //function prototype

This function prompts the user to enter an integer. After extracting data from cin, if cin.fail() is true, then print an error message and return -1. If a negative integer is entered, then print an error message and re-prompt the user; otherwise, return the integer.

If getInput() returns a -1, then the calling function should print the number of squares printed along with their average length using the printStats() function and terminate the program.

void printLine(char, char, int); //function prototype

This function prints a line for the square. The first char parameter is the end character. The second char parameter is the interior character. The third parameter is the line length.

Example usage.

int length = ...; //variable storing the square length

// print top line

printLine('+', '-', length);

// print interior line

printLine('|', ' ', length);

void printStats(int, int); //function prototype

This functions prints the number of squares printed and their average length. The first int parameter is the number of squares printed. The second int parameter is the total of the printed square lengths. This function prints a line having the following format.

X squares printed. Average length: Y.YY

Also it was my square assignment, but I couldnt do with in functions//

#include <iostream> using namespace std; int main(void){ int s,n; do{ cout << "Enter length between 0 and 64 (-1 to exit):" ; cin >> s; cout << "Length entered :"<< s <<endl; if (s<-1 || s>64 ){ cout << s <<" is invalid" <<endl; cout <<"Length must be between 0 and 64 inclusive, or enter -1 to exit\n"; continue; } if(s==-1) break; if(s==0){ cout <<" " <<endl; } int p=1; while( p<=s){ cout << ((p==1 || p==s)? '+':'|'); for( n=2 ;n<s;n++) cout << ((p==1 || p==s)? '-':' '); if(s>1) cout << ((p==1 || p==s)? '+':'|'); cout <<endl; p++; } }while(true); system("pause"); return 0; }