i have a function called showArray(int ar[], int numElements, and int numPerLine)
i am having some issues with creating the function properly so that the caller can call it. so far i have this:
/******************************
Function Name: void showArray(int ar[], int numElements, int numPerLine)
******************************/
void showArray(int ar[], int numElements, int numPerLine)
{
int i;`
while(numElements < 200)
{
i = ar[0];
cout << i;
i++;
}
if(numPerLine *= 2)
cout << endl;
an array will be passed through which has 200 elements. in main i have a symbolic const for the number of elements but dont know what passes through the other two arguments. any suggestions?!?! i know the function is coded incorrectly also! Thanks
33 2666
By the way, the function needs to display the elements of the array, several item per line as specified by the third argument. The seconds argument tells the function how many items are in the array, so it knows where to stop. i need to output a newline character when the number of items slready printed is a multiple of numPerLines. maybe the % operator? Thanks
Hi brady,
You have not defined a good condition for your while loop.You cannot predict
that your array will have 200 elements.Why not use instead something like: - int i=0;
-
int element
-
-
while(i<numElements)
-
{
-
element=ar[i];
-
ar[i-1]='\0';
-
cout<<element;
-
i++;
-
}
Hmm,for third argument you could integrate inside loop a counter which will count up to numPerLine and then it must become counter=counter%numPerLine and cout \n character to force the start of a new line.
Savage
Hello Savage,
Thanks for the reply! That makes a lot more sense then what i had. For the counter, can i just place that right after incrementing i? then maybe have a decision statement. im new with C++ so its a bit confusing.
Hi brady,
You have not defined a good condition for your while loop.You cannot predict
that your array will have 200 elements.Why not use instead something like: - int i=0;
-
int element
-
-
while(i<numElements)
-
{
-
element=ar[i];
-
ar[i-1]='\0';
-
cout<<element;
-
i++;
-
}
Hmm,for third argument you could integrate inside loop a counter which will count up to numPerLine and then it must become counter=counter%numPerLine and cout \n character to force the start of a new line.
Savage
Hello Savage,
Thanks for the reply! That makes a lot more sense then what i had. For the counter, can i just place that right after incrementing i? then maybe have a decision statement. im new with C++ so its a bit confusing.
Yes,that should do it!!!
Savage
Another question, is the '\0' a null value?
Hi brady,
You have not defined a good condition for your while loop.You cannot predict
that your array will have 200 elements.Why not use instead something like: - int i=0;
-
int element
-
-
while(i<numElements)
-
{
-
element=ar[i];
-
ar[i-1]='\0';
-
cout<<element;
-
i++;
-
}
Hmm,for third argument you could integrate inside loop a counter which will count up to numPerLine and then it must become counter=counter%numPerLine and cout \n character to force the start of a new line.
Savage
No,it's a terminating character which will ensure that you don't acsidently
cout previos element.
Savage
Yes thats right! Thanks for the refresher and thanks for your help! This function was driving me crazy! i'll post the final here in a minute and if you're around and happen to view the post and see a mistake could you let me know? i cant test it yet because im having issues passing arguments into the function. im getting the invalid conversion to int*, int or something like that
No,it's a terminating character which will ensure that you don't acsidently
cout previos element.
Savage
Yes thats right! Thanks for the refresher and thanks for your help! This function was driving me crazy! i'll post the final here in a minute and if you're around and happen to view the post and see a mistake could you let me know? i cant test it yet because im having issues passing arguments into the function. im getting the invalid conversion to int*, int or something like that
Please post just the troubleshooting part because if you post full code it will
be snipped by the moderators(see posting guidelines)
Savage
I didnt know that. and yes i will follow those guidlines. thanks for the fore warning
Please post just the troubleshooting part because if you post full code it will
be snipped by the moderators(see posting guidelines)
Savage
I didnt know that. and yes i will follow those guidlines. thanks for the fore warning
Always a pleasure..
Savage
Well i received a successful build after implementing the counter. just hope it works. here is what i coded after i was incremented:
while....
//body of loop previously posted
counter++;
if(counter = counter%numPerLine)
cout << "/n";
Always a pleasure..
Savage
Well i received a successful build after implementing the counter. just hope it works. here is what i coded after i was incremented:
while....
//body of loop previously posted
counter++;
if(counter = counter%numPerLine)
cout << "/n";
Here I can find 2 errors.
FIRST: - if(counter = counter%numPerLine)
is invalid.This condition will never become TRUE.
try using instead - if(counter==numPerLine) counter=counter%numPerLine,cout <<"\n";
SECOUND:
You might noticed that i used == when declaring a condition.Without these it would submit message:
"Possibly incorrect assigment ........"
Savage
Sorry for double post but i maked a mistake .The condition might become TRUE but I think that is not the best solution,anyway you would need to
"reset" a counter.
Savage
Yea that makes sense because im not assigning values. Can i code it like this:
if(counter==numPerLine)
counter=counter%numPerLine;
cout <<"\n";
is this the same as how you had it on one line?
Here I can find 2 errors.
FIRST: - if(counter = counter%numPerLine)
is invalid.This condition will never become TRUE.
try using instead - if(counter==numPerLine) counter=counter%numPerLine,cout <<"\n";
SECOUND:
You might noticed that i used == when declaring a condition.Without these it would submit message:
"Possibly incorrect assigment ........"
Savage
Not a prob. i can reset the counter like so, right?
if(counter==numPerLine)
counter=counter%numPerLine;
cout <<"\n";
counter = 0;
Sorry for double post but i maked a mistake .The condition might become TRUE but I think that is not the best solution,anyway you would need to
"reset" a counter.
Savage
Yea that makes sense because im not assigning values. Can i code it like this:
if(counter==numPerLine)
counter=counter%numPerLine;
cout <<"\n";
is this the same as how you had it on one line?
Yes,it's same.Operator ' ,' serves to declare actions that are correlated and it makes your code smaller.
Note:Use this operator only when actions are correlated or u might get lost
in code!!!
Savage
so instead of having lines of code like i just did it, the ',' operator lets you code, in our example, an entire loop on one line? very interesting. i didnt know that!
Yes,it's same.Operator ',' serves to declare actions that are correlated and it makes your code smaller.
Note:Use this operator only when actions are correlated or uou might get lost
in code!!!
Savage
Well,no one is borned with knowledge.
We exist to learn.
Savage
Another question for you, if you dont mind. my caller for that function is as followed:
showArray(storescores, 50, 8);
storescores is my array to hold scores from a file with 200 spaces available
50 and 8 are numbers i just made up to see if they would pass through
but im receiving a invalid conversion from int* to int. why would that be?
ha ha that is true. i like that
Well,no one is borned with knowledge.
We exist to learn.
Savage
Another question for you, if you dont mind. my caller for that function is as followed:
showArray(storescores, 50, 8);
storescores is my array to hold scores from a file with 200 spaces available
50 and 8 are numbers i just made up to see if they would pass through
but im receiving a invalid conversion from int* to int. why would that be?
Hmm,how have you declared storescores?
Savage
Yup, like so:
int storescores[200];
i had a symbolic constant of scores set to 200 and then i had the array like so:
storescores[scores];
but that was also giving me the same error
Hmm,how have you declared storescores?
Savage
Just a message that I've renamed the thread to be a bit more descriptive and not so verbose. :) Continue on!
MODERATOR
Thank you moderator, i was panicing and got a little keyboard happy. :)
Just a message that I've renamed the thread to be a bit more descriptive and not so verbose. :) Continue on!
MODERATOR
Yup, like so:
int storescores[200];
i had a symbolic constant of scores set to 200 and then i had the array like so:
storescores[scores];
but that was also giving me the same error
try declaring function as following: - void showArray(int *ar[],int numElements,int numPerLine);
Savage
That would be before main() right?
try declaring function as following: - void showArray(int *ar[],int numElements,int numPerLine);
Savage
That would be before main() right?
Yes,before main() and after it when defining what is function supposed to do.
(Thats,the part u first posted)
Savage
Got a successful build. i declared it before main as:
void showArray(int *ar[],int numElements,int numPerLine)
and i also changed the caller of the function to that also. is that correct?
Yes,before main() and after it when defining what is function supposed to do.
(Thats,the part u first posted)
Savage
Got a successful build. i declared it before main as:
void showArray(int *ar[],int numElements,int numPerLine)
and i also changed the caller of the function to that also. is that correct?
Yes it is.Bravo!!!
Savage
Now correct me if im wrong but shouldnt the caller of the function (in main) be something different from what i declared the function as (before main)?
Yes it is.Bravo!!!
Savage
Savage,
Thanks for all your help. greatly appreciated!
Now correct me if im wrong but shouldnt the caller of the function (in main) be something different from what i declared the function as (before main)?
Now correct me if im wrong but shouldnt the caller of the function (in main) be something different from what i declared the function as (before main)?
Just a litlle.The main differance is that when calling a function you don't
type like: - void showarray(int *ar[],int numOfElements,int numPerLine);
You type it like: - showarray(scores,200,50);
for e.g
Savage
Savage,
Thanks for all your help. greatly appreciated!
Just as I said:
Always a pleasure to help...
Savage
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Stormkid |
last post by:
Hi Group I'm trying to figure out a way that I can take two (two
dimensional) arrays and avShed and shed, and subtract the matching elements
in shed from avShed I've pasted the arrays blow from a...
|
by: lawrence |
last post by:
I wanted to test xml_parse_into_struct() so I took the example off of
www.php.net and put this code up on a site:
<?php
$simple = <<<END
<item>
|
by: vcardillo |
last post by:
Hello all,
Okay, I am having some troubles. What I am doing here is dealing with
an employee hierarchy that is stored in an array. It looks like this:
$employees = array( "user_id" => array(...
|
by: Sam Collett |
last post by:
How do I remove an item with a specified value from an array?
i.e. array values 1,2,2,5,7,12,15,21
remove 2 from array would return
1,5,7,12,15,21
(12 and 21 are NOT removed, duplicates are...
|
by: Mike S. Nowostawsky |
last post by:
I tried using the "toUpperCase()" property to change the value of an array
entity to uppercase BUT it tells me that the property is invalid. It seems
that an array is not considered an object when...
|
by: jr |
last post by:
Sorry for this very dumb question, but I've clearly got a long way to go!
Can someone please help me pass an array into a function. Here's a starting
point.
void TheMainFunc()
{
// Body of...
|
by: VK |
last post by:
Whatever you wanted to know about it but always were affraid to ask.
<http://www.geocities.com/schools_ring/ArrayAndHash.html>
|
by: Leszek |
last post by:
Hi.
Is it possible in javascript to operate on an array without knowing how mamy
elements it has?
What i want to do is sending an array to a script, and this script should
add all values from...
|
by: Jim Carlock |
last post by:
Looking for suggestions on how to handle bad words that might
get passed in through $_GET variables.
My first thoughts included using str_replace() to strip out such
content, but then one ends...
|
by: =?Utf-8?B?U2hhcm9u?= |
last post by:
Hi Gurus,
I need to transfer a jagged array of byte by reference to unmanaged
function, The unmanaged code should changed the values of the array, and when
the unmanaged function returns I need...
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
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
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
| |