Beginner C/C++

Moderators: None (Apply to moderate this forum)
Number of threads: 5430
Number of posts: 16951

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
do-while array Posted by Naitryn on 31 Mar 2011 at 3:39 PM
I'm trying to create a do-while statement, which is not my strongest suit. I'm trying to figure out how to get these two arrays to display properly but I'm not sure what I'm supposed to do. I don't have too much of the code down but I would love some pointers. Am I even heading in the right direction?

int main()
{
int points[5] = {62, 75, 100, 83, 85};
char grades[5] = {'D', 'C', 'A', 'B', 'B'};
int testScore = 0;
do
{
cout << "Enter a test score: ";
cin >> testScore;

while (testScore

system("pause");
return 0;
} //end of main function
Report
Re: do-while array Posted by pseudocoder on 1 Apr 2011 at 6:16 PM
testScore should check for a "sentinel" value; for example, if you prompt your user to enter data or -1 to quit, then testScore should test against -1.

do {
   cout << "Enter a test score (-1) to quit: ";
   cin >> testScore;

   // some something with testScore if it's not -1

} while(testScore != -1);


As far as the two arrays go, it's not clear what you're trying to accomplish in terms of how they relate to testScore if at all.

You *can eliminate* system("pause") by using
while(cin.get() != '\n'){}



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.