Question: Prompt user for a list of numbers.

Hi everyone,

I would like to know if it's possible to write a program that will allow the users to input the "amount" of number that they wish to enter, and then prompt the users to input the number "values" until the amount reaches the user input value and stop the program without using array; just use the "for" or "while" statement.
eg)

start
prompt user for the amount of numbers they wish to enter.
store amount in variable N
for (N=0; N<=N; N++)
prompt user for number values
store number values to X
end when the amount of input reaches N
end


...I have no idea if this is anywhere close to the right track lol.

or, is there a way for the program to stop when newline has reach N?

thank you all for the help
Last edited on
Something like this?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include <iostream>
#include <vector>
#include <string>

int main()
{
    std::vector<std::string> strVector;
    int amount = 0;

    std::cout << "Input the number of items you want" << std::endl;
    std::cin >> amount;


    std::string str;

    std::cin.ignore();

    int counter = 1;

    for(int i = 0; i < amount; i++)
    {
        std::cout << "#" << counter++ << ".";
        getline(std::cin, str);
        strVector.push_back(str);
    }

    counter = 1;
    std::cout << '\n';

    //Output Values
    for(int i = 0; i < amount; i++)
    {
        std::cout << "#" << counter++ << ".";
        std::cout << strVector[i] << std::endl;
    }

    return 0;
}
Topic archived. No new replies allowed.