Hey guys,
i am new to C++ and i was wondering if somone could help me out.
i am suposed to write a function that would do the folowing :
"Reads up to n integers from cin ( stopping when n integers have been read or when the user stops supplying more input, wichever comes first) and stored them in the array; returns the number of integers which were actually read."
Now i have learned in class how to do this by pre defining the values of the array but i have never tried inputting values into it.
This is what i have so far, but it will automaticcly read 0 till 100.. :(
SO i tried creating something else and thats what i got out of it :
Thanks for any help :)
i am new to C++ and i was wondering if somone could help me out.
i am suposed to write a function that would do the folowing :
"Reads up to n integers from cin ( stopping when n integers have been read or when the user stops supplying more input, wichever comes first) and stored them in the array; returns the number of integers which were actually read."
Now i have learned in class how to do this by pre defining the values of the array but i have never tried inputting values into it.
This is what i have so far, but it will automaticcly read 0 till 100.. :(
Code:
#include<iostream>
using namespace std;
int main ()
{
int array[100];
int t;
for (t=0; t<100; ++t)
array[t]=t;
for ( t=0;t<100; ++t)
cout<<"This is array ["<< t << "] :"<<array [t]<<"\n";
return 0;
}
SO i tried creating something else and thats what i got out of it :
Code:
include<iostream>
using namespace std;
int main ()
{
int array[100];
int n;
for ( n=0; n<100; n) // No incrementation :(
array[n]=n;
cout<<" Enter the values for your array:\n";
cin>>n; // is this even doable ???
return 0;
}
Thanks for any help :)
Comment