Random Name Program

Hi there,
I'm VERY new to C++ so bear with me on this.
I'm trying to write a program that asks the user for 5 friends names, and the program will randomly select which one to text. The problem occurs when I call the "getRandomName" function on line 33, the error message says:

"error: conversion from 'std::string*' to non-scalar type 'std::string' requested"

I'm not sure what this error message means. I know I am calling a function whose data type is string and the return type is string, but I don't see how this is a problem for the compiler.

Anyways, this is a homework question for my first programming class so I am not looking for the exact answer but any tips would be greatly appreciated!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include <iostream>
#include <string>
#include <cstdlib>
using namespace std;

string getRandomName (int userseed, string NameOfFriend)
{
    string result;
    srand(userseed);
    int RandomFriendNumber = rand() % 5;
    result = NameOfFriend[RandomFriendNumber];
    return result;
}


int main()
{
    int x; // counter variable
    int seed; //user determines size of seed.
    int SIZE = 5;
    string friendName[SIZE]; //5 memory spaces for 5 names of friends

    cout << "== Who Should I Text? ==" << endl;
    cout << "Enter seed" << endl;
    cin >> seed;

    for (x = 0; x < 5; x++)
    {
        cout << "Enter friend " << x << endl;
        cin >> friendName[x];
    }

    string result = getRandomName(seed, friendName);

    cout << "You should text: " << result << endl;

}
Last edited on
friendName is an array of strings, and you are passing it to getRandomName() which wants just a normal string.
Thank you! I really appreciate it! :)
Topic archived. No new replies allowed.