How can you Enter Data At Command Line and not use a Cout statement instead??

The user of the program should enter the input data or grades at the program execution command line..

How can you Enter Data At Command Line Instead of using a Cout statement like I did in the program below ?

Section of my program where I ask the user to enter in the data

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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
// function declarations

double getAverage (int *grades, int size);

double getMedian (int *grades, int size);

double getSd (int *grades, int size);

void sortGrades (int *grades, int size);

int
main ();


// Declaring variables

  int size, val;

// setting the precision to two decimal places

  std::cout << std::setprecision (2) << std::fixed;

// Getting the input entered by the user

  cout << "Please Enter Number of Grades For Child Process?? :";

  cin >> size;

// Creating array dynamically

  int *grades = new int[size];

/* Getting the inputs entered by the user

* and populate those values into array

*/

  for (int i = 0; i < size;)

    {

      while (true)

	{

	  cout << "Please Enter Grade again #" << i + 1 << ":";

	  cin >> val;

	  if (val < 0 || val > 100)

	    {

	      cout << "** Invalid.Must be between 0-100. **" << endl;

	      continue;

	    }

	  else

	    {

	      grades[i] = val;

	      i++;

	      break;

	    }

	}

    }

// calling the functions

  double avg = getAverage (grades, size);

  double median = getMedian (grades, size);

  double sd = getSd (grades, size);

  sortGrades (grades, size);



//displaying the average , median ,Standard Deviation
  cout << "Child process has completed the average computation" << endl;
  cout << "Child process can now display the Average! :" << avg << endl;

  cout << "Child process has completed the median computation" << endl;
  cout << "Child process can now display the Median!:" << median << endl;

  cout << "Child process has completed the Standard-deviation computation" <<
    endl;
  cout << "Child process can now display the Standard Deviation :" << sd <<
    endl;
Last edited on
Use the other form of main;

int main(int argc, char *argv[])

argc is the number of command line arguments, argv is an array of char-pointers that contain the arguments.

https://stackoverflow.com/questions/3024197/what-does-int-argc-char-argv-mean
Well, thats the answer the teacher wants. But what the student asked is how to enter the data at the command line, not how to rewrite the program.

Sounds like a job for cat input.txt and unix pipes to me. ;-)
Topic archived. No new replies allowed.