0
How to allow user to input as many as numbers separated by commas and then calculate the sum?
The program here restricts user to input 5 numbers followed by consecutive return keys. I could only declare a variable 'k' to store how many numbers the user wants to enter. But that again doesn't serve the purpose. int num=1; int number, k; int total=0; cout << "Enter how many numbers you want to add" << endl ; cin >> k; while(num<=k) { //calculate sum }
1 Respuesta
0
You could add every single input into an array, then use a for loop to iterate over every element and add them to each other.