Okay so I'm at the University of Alberta testing out programs (I'm 15 btw with a year of programming and no C++). Anyway we have to do this program where it asks the user to input 10 numbers (All on different lines) and then put all those numbers on a single line and then average out all the numbers. Now we have to use an array using a while or for loop (Well they want me to do both...) now I've never done any array type coding so this is obviously where I'm getting stuck at.
Need Help With Arrays...
Collapse
X
-
Arrays are covered in in any introductory book on C or C++.
I can only help you with specific problems.
Please read the posting guidelines. -
-
[CODE=cpp]int num;
num = 0;
while (num < 3) {
cout << "Enter a number: ";
cin >> num[0];
cout << "The 0th element in the array is " << num[0];
num = num + 1;
}[/CODE]
I know it's all wrong...but like I said I have never done this and have no idea.Last edited by r035198x; Aug 1 '07, 07:21 PM. Reason: Added code tags. Please don't forget them next timeComment
-
Originally posted by Vegiittoint num;
num = 0;
while (num < 3) {
cout << "Enter a number: ";
cin >> num[0];
cout << "The 0th element in the array is " << num[0];
num = num + 1;
}
I know it's all wrong...but like I said I have never done this and have no idea.Comment
-
Originally posted by VegiittoIs this the right start though?
int num[9];
while (num < 10) {
cout << "Enter a number: ";
cin >> num[0];
cout << "The 0th element in the array is " << num[0];
num = num + 1;
}
If not could you help out on what to put and where
All those things that were said in class really were important. For example, the fact that variables have one type. So you can't use the same variable to store both an int and an array. Do refer back to that link I gave you and see how the variables were being defined.Comment
-
Originally posted by VegiittoYou don't realize that I wasn't in a class with this like I've stated many times before this. I have not learned this stuff and am asking for help...this is not a class
I hope you are going over that link again now. It even has an example that covers more than half of what you want to do here.Comment
Comment