473,396 Members | 2,052 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Need Help With Arrays...

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.
Aug 1 '07 #1
18 1319
weaknessforcats
9,208 Expert Mod 8TB
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.
Aug 1 '07 #2
Okay help me with the code so the program asks and takes into an array the 10 numbers that he/she puts in.
Aug 1 '07 #3
weaknessforcats
9,208 Expert Mod 8TB
OK. Show me what you have so far.
Aug 1 '07 #4
Expand|Select|Wrap|Line Numbers
  1. int num;
  2.           num = 0;
  3.           while (num < 3) {
  4.           cout << "Enter a number: ";
  5.           cin >> num[0];
  6.           cout << "The 0th element in the array is " << num[0];
  7.           num = num + 1;
  8. }
I know it's all wrong...but like I said I have never done this and have no idea.
Aug 1 '07 #5
r035198x
13,262 8TB
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;
}

I know it's all wrong...but like I said I have never done this and have no idea.
You have done arrays in class right? Why not go through your notes first or an arrays tutorial before you try this again?
Aug 1 '07 #6
no that's the thing...I haven't done arrays or C++...so I have no idea how to do them
Aug 1 '07 #7
r035198x
13,262 8TB
no that's the thing...I haven't done arrays or C++...so I have no idea how to do them
Go through this then give your program another short.
Aug 1 '07 #8
Okay thanks...that helped with declaring the array but did nothing towards how I can ask the user 10 times to put a number then take it into the array
Aug 1 '07 #9
r035198x
13,262 8TB
Okay thanks...that helped with declaring the array but did nothing towards how I can ask the user 10 times to put a number then take it into the array
Refer back to your previous problem. The one with the while and if elses.
Aug 1 '07 #10
Is 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
Aug 1 '07 #11
r035198x
13,262 8TB
Is 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
That won't help you to get this done on your own in the future.
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.
Aug 1 '07 #12
You 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
Aug 1 '07 #13
r035198x
13,262 8TB
You 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
Yes, sometimes I'm slow to understand some things. Thanks for repeating.
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.
Aug 1 '07 #14
Don't know if that was sarcasm or not...but yes I'm going over it
Aug 1 '07 #15
r035198x
13,262 8TB
Don't know if that was sarcasm or not...but yes I'm going over it
It was not. If I wasn't about to knock off I'd prove it to you.
Anyway you're probably too busy reading that link to pay attention ...
Aug 1 '07 #16
Knock off? What is that?
Aug 1 '07 #17
r035198x
13,262 8TB
Knock off? What is that?
Go home and get some sleep. That's what I meant. It's not a good phrase to use so don't use it.
I'm going home now (use that).
Aug 1 '07 #18
Ok.. I hope this code will help you..
<Removed>
Aug 2 '07 #19

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Golf Nut | last post by:
I am finding that altering and affecting values in elements in multidimensional arrays is a huge pain in the ass. I cannot seem to find a consistent way to assign values to arrays. Foreach would...
41
by: Psykarrd | last post by:
I am trying to declare a string variable as an array of char's. the code looks like this. char name; then when i try to use the variable it dosn't work, however i am not sure you can use it...
2
by: Pasacco | last post by:
dear I want to ask help on this problem. Array a is partitioned into a0 and a1 in main(). Then a1 is partitioned into a2 and a3 in th_partition() function. And I think this problem is something...
1
by: John Smith | last post by:
I have a two dimentional char array. Before filling it using strtok(), I reset its elements to '\0' using two nested for loops. The code works as I hope it would but I wonder whether I really need...
2
by: Thomas Connolly | last post by:
Anyone know if there is a C# equivallent to: enum { LIFFE_SIZE_AUTOMARKETREF = 15 }; typedef char LiffeAutoMarketReference ; Thanks,
8
by: hothead098 | last post by:
ASSIGNMENT (4) USING AND MANIPUPATING ARRAYS (Chapter 10 material) For this assignment you are to: 1) Create and manage arrays a) One of type integers (containing 10 elements). b) One of...
23
by: vinod.bhavnani | last post by:
Hello all, I need desperate help Here is the problem: My problem today is with multidimensional arrays. Lets say i have an array A this is a 4 dimensional static array.
1
by: rllioacvuher | last post by:
I need help with a program. I have implemented that following header file with an unordered list using one array, but i need to be able to use an ordered list and 2 arrays (one for the links and one...
6
by: junk | last post by:
Senerio: I have a custom user control which contains two control arrays. The user control has a group box in which the two control arrays are dynamically built. The two control arrays are...
0
by: sumalats | last post by:
Hello, I need to use Visual basic to acquire some data through the serial port, store it etc. As I am just getting acquainted with VB6 I need some help. My Controller board (8 bit micro) sends...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.