C++ please help..I made squrea in main, I need to re-do that assignment with using function?
-
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 and here is my squares assingment #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; }
-
Answer:
That's because your variables weren't set up properly. Try adding some new variables.
Lebron at Yahoo! Answers Visit the source
Related Q & A:
- Why cant i view my contacts display image? please help if you know ,thanks?Best solution by Yahoo! Answers
- I need help on what I need to buy or do.Best solution by Yahoo! Answers
- I still dont understand WHERE do I type in the name to visit someones blog I need Details please.Best solution by Yahoo! Answers
- I did something really bad and now i need help please help me.Best solution by Yahoo! Answers
- I need help with my camera, please.Best solution by Yahoo! Answers
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.