Hi i am a begginer in learning computer science and i received a assignment question on arrays.

The question asks me to split the characterArray= joe,487 into two seperate variables, one is a variable called idArray where the numbers 487 will go, then i have to have three spaces for the comma and then the final variable is nameArray which the name joe should go.
my problem is that i do not know how to write this into a pseudocode algorithm.

any help would be greatly apreciated?

Dani AI

Generated

A concise solution and a few practical notes that extend the suggestions already in the thread: the goal is to turn the single text block "joe,487" into two variables named nameArray and idArray. was correct to look for the comma as a delimiter; 's C++ example and 's array explanation give context about arrays. Below are two clear pseudocode approaches — one that uses a high-level split (if allowed for the assignment) and one that shows the full character-scan so the logic is explicit.

// Method A — use a built-in split (shortest)
input <- "joe,487"
parts <- SPLIT(input, ',')          // parts[1] = "joe", parts[2] = "487"
nameString <- TRIM(parts[1])
idString   <- TRIM(parts[2])

nameArray <- TO_CHAR_ARRAY(nameString)   // ['j','o','e']
idArray <- EMPTY_ARRAY
for i from 1 to LENGTH(idString)
    if IS_DIGIT(idString[i]) then
        APPEND(TO_INT(idString[i]), idArray)
    else
        // record or ignore non-digit per spec

PRINT nameArray
PRINT idArray

// Method B — manual scan (no built-ins)
input <- "joe,487"
nameString <- ""
idString <- ""
foundComma <- FALSE
for i from 1 to LENGTH(input)
    ch <- input[i]
    if ch == ',' then
        foundComma <- TRUE
    else if not foundComma then
        nameString <- nameString + ch
    else
        idString <- idString + ch

// then convert nameString -> nameArray, idString -> idArray as above

Extra notes: trim whitespace around fields; validate that idString contains only digits before converting; handle the missing-comma case by treating the whole input as a name or flagging an error; if the assignment expects fixed-width blocks (the "three spaces for the comma" phrasing), parse by substring positions instead of splitting. The two methods above cover both classroom-style pseudocode and low-level logic tracing that graders often expect.

Recommended Answers

All 6 Replies

I can not understand what you are after, this does not sound like problem of finding the correct algorithm for problem, it sounds more like you already have the pseudo code algorithm given to you.

All that is give to me is the array joe,487 in blocks and i have to write a solution algorithm that splits the joe away from 487.
And then i have to print the idArray and nameArray .

So you must write algorithm to separate the letters 'joe,' from letters '487'? It does look awfully implementation oriented to really be pseudocode.

suppose you wanted to find ',' in the array "hello,all"

so the pseudocode would be :-

foreach char c in array
    if c = ","
        print "found you"

you can use this template to solve your question

I,can not understand you but you need to
jeo,487' block and logrithem folow I give you wen example how to use arry

// to accept a list of numbers int a 1-d array, find their sum and average and display them.
#include <iostream.h>
int main()
{
    int a[10], i, n, sum;
    float avg;
        cout<<"Enter no of Elements [1-10] \n";
        cin>>n;
        cout<<"Enter "<<n<<"numbers \n";
        for (i=0; i<n; i++)
             cin>>a[i];
             // finding the sum and average begins
         sum=0;
         for (i=0; i<n; i++)
         sum=sum+a[i];
         avg=(float)sum/n;

         // finding the sum and average ends

         cout<<"the sum is "<<sum<<endl;
         cout<<"the average is "<<avg<<endl;
return 0;
}

a is declared to be an array of int type and of size 10. A maximum of 10 numbers can be written into the array.
The variables n, i and sum are declared to be variables of int type where n is to collect the number of values to be read into the array a, which lies within 1 and 10, i is to traverse all of the values in a, and sum is to collect the sum of the values in a.
The variable avg is declared to be a variable of float type and it is to collect the average of values in a.

In the process of finding the sum of all of the n values, initially sum is set to 0. A for loop is used to select each number in the array and it is added to sum with the statement sum=sum+a[i].
The statement avg=(float)sum/n; on its execution, assigns the average value to avg. Note that you have used type-casting to convert sum forcibly to float to get the exact result. Otherwise, the expression sum/n produces only integral part of the quotient since both sum and n are integers. Both sum and avg are then displayed.

http://www.cplusplus.com/doc/tutorial/arrays/

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.