This is my first time posting on the forums. I am a beginner in the C++ language and been having some difficulty troubleshooting my assignment for class. I have been working with while loops and nested while loops, but can not seem to grasp the process. Here is what I am having issues with.
// get user info
cout << " 100 Meter Race Results " << endl;
cout << " Are you ready to enter data for the first heat(Y/N): " << endl;
cin >> answer;
// set perimeters.
while (answer != 'N')
{
while (points != -1)
{
runner++;
heat = 1;
cout << " Enter time for runner " << runner << " in Heat " << heat << " (-1 to end heat) " << endl;
cin >> points;
}
if (points > mostpoints)
mostpoints = points;
if (points < leastpoints)
leastpoints = leastpoints;
cout << " Best time in Heat " << heat << " was runner # " << mostpoints << endl;
cout << " Are you ready to enter data for the first heat(Y/N): " << endl;
cin >> answer;
}
system("pause");
return 0;
}
I can not seem to get the Y/N loop to execute. I apologize for the layout of the post. I am trying to figure out how to format in code. If someone could please give me a hint of why my outer while loop is not working it would be greatly appreciated.
Sorry about that. The program is supposed ask the user for time of the runners in each heat. (100 meter race) Then display the runner numbers and their race times using a sentinel-controlled while loop. Then add the code to handle multiple heats.
#include <iostream>
usingnamespace std;
int main()
{
char answer;
int total = 0, points = 0;
int runner = 0;
int heat = 0;
double mostpoints = 1;
double leastpoints = 1;
// get user info
cout << " 100 Meter Race Results " << endl;
cout << " Are you ready to enter data for the first heat(Y/N): " << endl;
cin >> answer;
// set perimeters.
while (answer != 'N')
{
while (points != -1)
{
runner++;
heat = 1;
cout << " Enter time for runner " << runner << " in Heat " << heat << " (-1 to end heat) " << endl;
cin >> points;
}
if (points > mostpoints)
mostpoints = points;
if (points < leastpoints)
leastpoints = leastpoints;
cout << " Best time in Heat " << heat << " was runner # " << mostpoints << endl;
cout << " Are you ready to enter data for the first heat(Y/N): " << endl;
cin >> answer;
}
system("pause");
return 0;
}
I understand that this is still a work in progress by far, but at this moment I am just trying to figure out why my nested while loop is working but not the outer loop.
Just exactly what is it you are having problems with? I compiled it (well, I had to comment out system("pause")) and ran it. It seems to work fine for me, or am I missing something?