Need code for simple demo

a c++ program that initially takes an integer value from the user as the loop’s limit. It means that the loop will execute the same times as the input from the user. The loop will then take integer values as input from the user until it reaches loop limit.
use only one variable which will be used to take input repeatedly from the user inside the loop. It means its not allowed to use the array or multiple variables for this purpose. After that program will calculate sum of entered values, their average, minimum and maximum values along with position on which these values were entered.
Is this the kind of "demo" that one has to "demonstrate" to a teacher, in return for a grade?
nope, I'm teacher myself. i'll give the demo
Its giving me errors



prog.cpp: In function 'int main()':
prog.cpp:7:5: error: expected ';' before string constant
cout"Enter loop limit : a";
^
prog.cpp:8:5: error: expected ';' before string constant
cout"Enter 1st value :";
^
prog.cpp:10:5: error: expected ';' before string constant
cout"Enter 2nd value :";
^
prog.cpp:12:5: error: expected ';' before string constant
cout"Enter 3rd value :";
^
prog.cpp:14:5: error: expected ';' before string constant
cout"Enter 4th value :";
^
prog.cpp:16:5: error: expected ';' before string constant
cout"Enter 5th value :";
^
prog.cpp:19:5: error: expected ';' before string constant
cout"The sum of entered values = "iendl;
^
prog.cpp:20:5: error: 'iendl' was not declared in this scope
i=i/iendl;
^
prog.cpp:21:5: error: expected ';' before string constant
cout"Average value ="iendl;
^
prog.cpp:23:1: error: expected '}' at end of input
}
^





1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include<iostream>
using namespace std;
int main()
{
int i;
cout"Enter loop limit : 5"endlendl;
cout"Enter 1st value :";
cin>>i;
cout"Enter 2nd value :";
cin>>i;
cout"Enter 3rd value :";
cin>>i;
cout"Enter 4th value :";
cin>>i;
cout"Enter 5th value :";
cin>>i;
i=i+i+i+i+i; 
cout"The sum of entered values = "iendl;
i=i/5;
cout"Average value ="iendl;
Last edited on
There are some pretty obvious typos there:

"endlendl

"iendl

"iendl

Also, some missing stream operators. You might find it helpful to take a look at:

http://www.cplusplus.com/doc/tutorial/basic_io/

You should take the time to actually read those compiler errors, as they should give you some idea what the problem is, and will certainly tell you what line the problem is on.
Last edited on
I won't say anything about the teacher part, but ok.

When you say loop, you'll actually want a loop structure in there (i.e. for, while, do while).

In this case, I would most likely use a for loop because that's the easiest for the purposes of this "demo"

1
2
for( int a = 0; a < nSize; ++a )
    cin >> b;


There's some extra parts you'll need to do the demo, sum and average being the easiest, and min/max values and positions being the hardest.
Topic archived. No new replies allowed.