adding count to a var problem =/

Ok I am trying to do a while statement and cannot figure out how to add the count to a name of an input =/ By looking at it you will get the just of what I am trying to accomplish.. Maybe one of yall can help me.


#include <iostream>
#include <iomanip>
#include <cstring>
using namespace std;

int main (){
const int SIZE = 81;
char runner, runner1, runner2, runner3;
double time, time1, time2, time3;
int count;

count = 1;

while (count != 3) {
cout << "\nEnter runner number " << count << "\'s name:";
cin.getline(runner << static_cast<char>(count), SIZE);
cout <<"\nEnter his/her time:";
cin >> time << static_cast<char>(count);
count += 1; }



I have tried various different ways to no prevail =/ for example:

cin >> time(count);
cin >> time[count];

and others that I have forgotten by now. We are not getting into the do/while loops until another week or 2 in school but I figure it can be done kinda like html but just can't figure it out =/

This is just the begging of the code, in the end I want to take 3 runners names and times then display them in order from best time to last. I had it written the long way before but I know its a waste of typing doing every cout/cin for all 3 runners/times.. I am not asking for any code though for my project just how too add a count to my variable so it stores each new variable into memory so I can display them later. I tried looking with a search to no success =(

Thanks in advance for any replies =]
For the love of all that's holy, what are you doing?
cin.getline(runner << static_cast<char>(count), SIZE); cin >> time << static_cast<char>(count);

What are those two lines supposed to mean?
lol I was playing around with different things to the point of exhausting anything I could think of. I am trying to turn variable char runner into like runner1, runner2, runner3 and same for time (time1, time2, time3) till loop runs thru then able to display them later.. I prob have it all fugged up =(



just trying to figure out how to add my count to the end of my variables so I can recall and display them later I guess easiest way to say it

I could just ignore the loop and do:
cout <<"enter runner1 name";
cin >> runner1;
cout <<"enter runner1 time";
cin >> time1
cout << "enter runner2 name";
cin >> runner2;
cout << "enter runner2 time";
cin >> time2;
cout << "enter runner3 name";
cin >> runner3;
cout << "enter runner3 time";
cin >> time3;

but trying to get rid of the repetitive nature... get it?
Last edited on
Okay, I think I understand what you mean.
You want to modify the name of 'runner' at run time so it becomes runner1, runner2, etc.
Yeah, that's not how things work.

Variable names are there only for your benefit. At run time they don't exist and there is no way of knowing what a variable was called at compile time.

What you need to do here is use an array.
Read this: http://www.cplusplus.com/doc/tutorial/arrays.html
OK, thanks for your help =]
Topic archived. No new replies allowed.