Smallbasic program | Learnok.com

Smallbasic program

How do you write a program that will store names into a 1D array using a WHILE loop As a new name is entered it will therefore be added to the end of the array. The user can keep adding names until they enter the dummy name ‘exit’. Once this has been entered display the number of names entered and any duplicate names. I've just started computing and I'm very stuck. Thank you :)

Answers

If you are using C++ or any other language higher than C, then the steps would be- 1. Declare the array 2. Analise the no. of inputs / the case to end loop in case of undefined entries.

int main() { string arr[ 100 ]; string input = "hello"; int count = 0; while( input != "exit" && count < 100 ) { cin>>input; arr[ count ] = input; count++; } }

There are other ways too!! Comment if you need any help!! :)

Answered by Sparsh Rana

We have mentors from

  • Suffolk University Boston
  • University of California, Los Angeles
  • New York University
Contact support