I have been working on this problem and I'm stumped! can anyone help me please!
The purpose of this assignment is to provide you with some additional practice in using some of the operators and control constructs available in C++. For the assignment you are to write a program that generates some basic statistics on a set of input values. The program begins by first prompting the user to specify the number of values, say n, that are to be processed. Once this value has been determined program should prompt the user to enter n values, with one prompt per value to be entered.
For each of the n values entered, the program should perform the following actions (without performing any additional output per value:
• Maintain a running total value
• Determine if the value is negative
• Determine if the value is an integer
• If the value is an integer, determine whether it is even or odd
After all of the values have been input to the program, the program should then output the following statistics concerning the input:
• The number of values entered
• The sum of the values entered
• The average of the values entered
• The number of negative values entered
• The number of even values entered
• The number of odd values entered
im trying first to set up the index for the j floating point values. the loop works, however i can't get it to maintain a running total, as well as the other things mentioned above, your help would really be appreciated, I've been completely stumped by this problem
A running total? You would just define an int variable, and increment it by 1 every time your loop runs (place the counter++ wherever you want), and output it if you want.
note that counter++ is the same as counter = counter + 1
so if you start with counter = 0
it ends up being 0 = 0 + 1
counter is now equal to 1
Then your loop starts again
counter is now equal to 1
1 = 1 + 1
counter is now equal to 2
#include <iostream>
usng namespace std;
int main()
{
double i, n;
float j;
cout<< "Please specify the amount, n, values to be processed: " <<endl;
cin >> n;
int counter=0;//ADD THIS LINE
for(i = 1 ; i <= n; i++){
cout << "the value of j is: " <<endl;
cin >> j;
counter++;//ADD THIS LINE TOO
for(j; j <= i; j++){
if(i >= n)
break;
}
}
cout<<"j came up "<<counter<<" times.";//ADD THIS LINE TOO
system("pause");
return 0;
}
ok so i add the counter outside the for loop, I was initially adding into the for loop and it was causing all sorts of problems. now how can i have the program add up all the various floating values i assign to j. i.e
let n = 5
then j1 =10.1
j2 = .1
j3 = 2
j4 = 3
j5 = 1
#include <iostream>
#include <cstdlib>
usingnamespace std;
int main()
{
int n;
double j;
cout << "Please specify the amount, n, values to be processed: " << endl;
cin >> n;
double total = 0;
for (int i = 0 ; i < n; i++)
{
cout << "enter value of j: " << endl;
cin >> j;
total += j;
}
cout << "total of the values is: " << total << endl;
system("pause");
return 0;
}
The average is simply total/n.
The other requirements need additional code to test specific conditions (odd, even, negative etc.) and a separate count (an integer value) for each category.