Apr 27, 2016 at 2:14am UTC
I get an error anytime I try to put in a value for a variable in rAccount. error message is:
"main.cpp: In function 'rAccount reg()':
main.cpp:65:16: error: expected primary-expression before 'rAccount'
cin >> string rAccount.name;
^
main.cpp:65:16: error: expected ';' before 'rAccount'
main.cpp:66:10: error: expected unqualified-id before '.' token
rAccount.actNum = rand() % 100000 + 999999;
^
main.cpp:67:10: error: expected unqualified-id before '.' token
rAccount.actBal = 0.0;"
code is as follows:
#include <iostream>
#include <string>
#include <cstdlib>
using namespace std;
struct rAccount
{
string name;
int actNum;
float actBal;
};
int main()
{
reg();
return 0;
}
rAccount reg()
{
cout << "Enter your name: ";
cin >> rAccount.name;
rAccount.actNum = rand() % 100000 + 999999;
rAccount.actBal = 0.0;
cout << endl << "Your account details are: " << endl;
//cout << reg();
}
Last edited on Apr 27, 2016 at 2:38am UTC
Apr 27, 2016 at 3:38am UTC
rAccount
is the type. It is not an identifier (name of an instance of that class).
So, you when you try to access rAccount.name
, you're not actually accessing the member of any instance of that class. Also, your reg()
function expects to return an rAccount
object, but it doesn't return anything.