Member Avatar for chudapati09

I have to write a program where the user would input multiple numbers.
This is what it could look like.

3 29 98 78 88 100
9 70 73 81

The input is never the same, and I just need to access each number one at a time.
My problem is that I don't know how to store more than one character in a variable.
This is what I have currently:

char inputA;
char inputB;

cin.get(inputA);
cin.get(inputB);

I would use this function, but this function wouldn't work because the number of inputs the user would put into the console would be different all the time.

Example input: 3 29 98

cin << num1 << num2 << num3;

And finally I need to use these numbers for calculations, so I can't concatenate them into a string either. I can't use arrays or create my own functions.

Sorry if this doesn't make sense its 2:32 AM I'm about to die from lack of sleep.

1) Assuming you need to "access each number one at a time", put the program in a loop. Inside the loop, read a number, use it, then when the loop returns to the beginning, the next number will be read.

2) If you need to use multiple numbers at the same time, the only appropriate way is to use an array. But from your description, this is not your case.

Member Avatar for chudapati09

1) Assuming you need to "access each number one at a time", put the program in a loop. Inside the loop, read a number, use it, then when the loop returns to the beginning, the next number will be read.

2) If you need to use multiple numbers at the same time, the only appropriate way is to use an array. But from your description, this is not your case.

Okay I have a loop, but how can I access each number?

I don't see a loop... I see a question. Read the member rules -- especially the Keep it Clear section.

Member Avatar for chudapati09

I was over complicating it. I ended up just doing this:

while(cin){
  cin << temp;

  //then I just had a couple of if statments to do what I needed to with that  value

}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.