Answer to Question #302305 in C++ for Program Training

Question #302305

First, read in an input value for variable numVals. Then, read numVals integers from input and output each on the same line with the character ", " between each value. End with a newline. 

Note: ", " should not be at the beginning or end of the output.

Ex: If the input is 4 -60 -35 -15 -45, the output is:

-60, -35, -15, -45


1
Expert's answer
2022-02-24T12:18:52-0500
#include <iostream>
#include <string>

using namespace std;

int main()
{
	int numVal;
	cout << "Input: ";
	cin>> numVal;
	string* numbers=new string[numVal];
	for (int i = 0; i < numVal; i++)
	{
		cin >> numbers[i];
	}
	for (int i = 0; i < numVal; i++)
	{
		if(i== numVal-1)
			cout<<numbers[i];
		else
			cout << numbers[i] << ",";
	}
	delete[] numbers;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog