hello everyone can someone help me about array plsss i really need help right now
using one-dimensional array. create a program that will count the number of the same intries in a series number based on the user specific no. to count
EXPECTED output
Enter no.1:2
Enter no.2:1
Enter no.3:1
Enter no4:2
what number to v=count?1
total number 1 is 2
should use a counter
i appretiate those who will answer
this is my code
#include<iostream>
using namespace std;
int main()
{
int n,hn,nc;
int i;
int count;
float totaln;
count=0;
cout<<"ENTER MANY NUMBERS TO INPUT?:"<<endl;
cin>>hn;
for(i=1;i<=hn;i++)
{
cout<<"ENTER NUMBER :"<<i<<":";
cin>>n;}
cout<<"WHAT NUMBER TO COUNT:"<<endl;
cin>>nc ;
count=0;
totaln+=n;
First off, please put your code in code <> brackets. The button for this can be found under the Format box to the right of the text window when creating/editing a thread.
Secondly, you haven't even attempted to implement your array. :( As it stands, your user will enter in "n", "hn" times in a row, but "n" will just be overwritten each time. It is stored nowhere. Also, variables such as "i" that are to be used within a for loop can be completely defined within the for loop itself, unless you need to reference the last value of "i" later on or something. Therefore, your for loop becomes:
1 2 3 4
for(int i=1;i<=hn;i++)
{
}
Within your first for loop you should be using "i" to also place the values within your array (which you haven't declared yet). Technically you'll be using i-1, since you'll want to start at 0, and not 1, since someArray[0] will coincide with the first spot in the array.
susied this is not codding for arrays u should declare first array.......like A[10];..........etc then u use for loop for it
learn tutorial of arrays......
int a[5];
int count=0;
int sum=0;
for(int i=1;i<=5;i++)
{
cout<<"enter number";
cin>>a[i];
sum=sum+a[i];
count++;
}
cout<<count<<endl;
cout<<"array sum="<<a[i];
#include<iostream>
using namespace std;
int main()
{
string name[50]={};
int s[]={};
int i;
int hn;
int l;
int k;
int n;
int largest;
int smallest;
float average;
cout<<"ENTER MANY many students?:"<<endl;
cin>>hn;
for(i=1;i<hn;i++)
{
cout<<"ENTER name of students :"<<i<<":" ;
cin>>n;{
cout<<"ENTER SCORE:";
cin>>l;}
here's my new code right now
#include<iostream>
using namespace std;
int main()
{
int a[]={};
int count=0;
int sum=0;
int i,hn,w;
cout<<"ENTER MANY NUMBERS TO INPUT?:"<<endl;
cin>>hn;
for(i=1;i<hn;i++)
cout<<"ENTER NUMBER :#"<<i-1;
cin>>a[i];
cout<<"WHAT NUMBER TO CUONT:"<<endl;
cin>>w;
{
sum=sum+a[i];
count++;
}
cout<<count<<endl;
cout<<"TOTAL:"<<a[i];
system("PAUSE");
#include<iostream>
usingnamespace std;
int main()
{
int a[]={};
int count=0;
int sum=0;
int i,hn,w;
cout<<"ENTER MANY NUMBERS TO INPUT?:"<<endl;
cin>>hn;
for(i=1;i<hn;i++){
cout<<"ENTER NUMBER :#"<<i-1;
cin>>a[i];
cout<<"WHAT NUMBER TO CUONT:"<<endl;
cin>>w;
{
sum=sum+a[i];
count++;
}
cout<<count<<endl;
cout<<"TOTAL:"<<a[i];
system("PAUSE");
}
modoran, read it again and try to translate the phrase "Enter many numbers to input?". There is a way not-to-use std::vector I know, but I won't say which one because...
#include <iostream>
usingnamespace std;
int main()
{
int Count = 0;
int Numbers = 0;
int Num = 0;
int w;
cout << "Enter many numbers to input ?" << endl;
cin >> Numbers;
for (int i = 0; i<Numbers; i++) {
cout << "Enter #" << (i+1) << endl;
cin >> Num;}
cout<<"WHAT NUMBER TO CUONT:"<<endl;
cin>>w;
Count += Num;
cout << "The sum of total " << w << " is " << Count << endl;
system("PAUSE");
}
but it doesn't work :(
when i enter
Enter many numbers to input ? :2
Enter #1:2
Enter #:2 3
WHAT NUMBER TO CUONT: 5
total number 5 is 6
instead of like this
total number 5 is 0
beacuse i 5 has not belong to what i enter
#include <iostream>
usingnamespace std;
int main()
{
int Count = 0;
int Numbers = 0;
int Num = 0;
int Search = 0;
cout << "How many numbers do you want to enter ?" << endl;
cin >> Numbers;
cout << "What number occurence to search for ?" << endl;
cin >> Search;
for (int i = 0; i < Numbers; i++) {
cout << "Enter #" << (i+1) << endl;
cin >> Num;
if (Num == Search)
Count++;
}
cout << "Total occurences of number '" << Search << "' is " << Count << endl;
return 0;
}
ahhh .. sorry for disturb but its always answer 0. Im trying to understand this but i dont how to be like this(correct answer)
how many want you to enter?: 4
enter #1: 2
enter #2: 2
enter #3: 2
enter #4: 2
What number to be count?: 2
the total number of 2 is "4"
hmmmm