| | |
function issues
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
I have this program it allows the users to enter a name and a score it saves all the names to one array and all the scores to another. The program then displays all the names and scores in a list.
I want to have the code for displaying the the list of names and scores be in a separate function. The code works in the int main() function but as soon as i put it in a separate function the code no longer works
here is my code i would just like to know what i need to do to make the list work in the displayfunctiion() instead of the int main () function
Thanks for you help
I want to have the code for displaying the the list of names and scores be in a separate function. The code works in the int main() function but as soon as i put it in a separate function the code no longer works
here is my code i would just like to know what i need to do to make the list work in the displayfunctiion() instead of the int main () function
C++ Syntax (Toggle Plain Text)
#include <iostream> #include <string> #include <math.h> using namespace std; double DisplayArrays(string studentName, int score) { studentName[20]; score[20] cout << "Name " << "Score" << endl; cout << "=============================" << endl; for (int n = 0; n < 20; n++) { if (studentName[n] == "stop"|| score[n] == -1) { break; } cout << studentName[n] << " " << score[n] << endl; } } int main() { const int ARRAYTIME = 20; string studentNames[ARRAYTIME]; int scores[ARRAYTIME]; cout << "To end the loop enter 'stop' as student name and '-1' as score" << endl; for (int i = 0; i < ARRAYTIME ; i++) { cout << "Enter student name: "; cin >> studentNames[i]; cout << "Enter score: "; cin >> scores[i]; cout << endl; if (studentNames[i] == "stop" || scores[1] == -1) { break; } } cout << endl; DisplayArrays(studentNames[], scores[]); /***cout << "Name " << "Score" << endl; cout << "=============================" << endl; for (int n = 0; n < ARRAYTIME; n++) { if (studentNames[n] == "stop"|| scores[n] == -1) { break; } cout << studentNames[n] << " " << scores[n] << endl; } *********/ return 0; }
Thanks for you help
Your []'s are in the wrong spot. Say
and
Hope this helps.
C++ Syntax (Toggle Plain Text)
DisplayArrays( studentNames, scores );
C++ Syntax (Toggle Plain Text)
double DisplayArrays( string studentName[], int score[] )
•
•
•
•
I have this program it allows the users to enter a name and a score it saves all the names to one array and all the scores to another. The program then displays all the names and scores in a list.
I want to have the code for displaying the the list of names and scores be in a separate function. The code works in the int main() function but as soon as i put it in a separate function the code no longer works
The more vague you are, the more useless help is.
Thank you for finally using CODE tags. Now we need better titles...
The 3 Laws of the Procrastination Society:
1) Never do today that which can be put off until tomorrow
2) Tomorrow never comes
1) Never do today that which can be put off until tomorrow
2) Tomorrow never comes
![]() |
Similar Threads
- Send data on a serial port (C++)
- Disclaimer Messages (JavaScript / DHTML / AJAX)
- home work help funcations and arry issues (C)
- Login Script Issues (PHP)
- Problem passing structure with array into function (C)
- Problem with string variable in void prnt function (C++)
- No "Data & Time" Function (Windows 95 / 98 / Me)
- Counter issues (C)
Other Threads in the C++ Forum
- Previous Thread: Need text file related help
- Next Thread: using GetPixel() outside client window
| Thread Tools | Search this Thread |
Tag cloud for C++
api application array arrays based beginner binary bmp c++ c/c++ calculator char char* class classes code compile compiler console conversion convert count data delete deploy dll download dynamiccharacterarray email encryption error file format forms fstream function functions game givemetehcodez graph homeworkhelp iamthwee ifstream input int java lib library lines list loop looping loops map math matrix memory newbie news number numbertoword output pointer problem program programming project python random read recursion recursive reference return rpg search simple sorting spoonfeeding string strings struct temperature template templates text text-file tree url variable vector video visual visualstudio void win32 windows winsock wordfrequency wxwidgets






