Code:
#include <iostream>
using namespace std;
int main() {
int noOfArray = 100;
int integerVariable[noOfArray];
for (int i = 0; i < noOfArray; i++)
{
while (!(cin >> integerVariable[i]))
{
cin.clear();
cin.ignore(numeric_limits<streamsize>::max(), '\n');
cout << "Please enter a valid int!\n";
}
}
cout <<"\n\n\nYou entered:\n";
for (int i = 0; i < noOfArray; i++)
{
cout << integerVariable[i] <<"\n";
}
system("pause");
return 0;
}
Well, I got that to work, but the problem is that now I have to enter 100 numbers or what ever I sett it to. But how can I make this a bit more dynamic? So that the user can decide when he wants to stop typing.
Aslo, is there a way to quarry the size of an array?
Or should I just aks the user for how many numbers he would like to use, than finish the program and move on?
Code:
#include <iostream>
using namespace std;
float averageNo(int integerVariable[],int noOfArray);
int main() {
int noOfArray;
cout << "How many numbers would you like to use for this program?\n";
cin >> noOfArray;
int integerVariable[noOfArray];
cout << "\n\nEnter you numbers:\n";
for (int i = 0; i < noOfArray; i++)
{
while (!(cin >> integerVariable[i]))
{
cin.clear();
cin.ignore(numeric_limits<streamsize>::max(), '\n');
cout << "Please enter a valid int!\n";
}
}
//Not working
cout << averageNo(integerVariable[noOfArray],noOfArray);
system("pause");
return 0;
}
int averageNo(int integerVariable[],int noOfArray)
{
cout <<"\n\n\nYou entered:\n";
for (int i = 0; i < noOfArray; i++)
{
cout << integerVariable[i] <<"\n";
}
char a = 's';
return a;
}