• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Multiple C++ questions

idNut

Diamond Member
I have to do this program without classes so all replies, don't use classes. How do you make multiple use of multiple objects in the same function but at different times? Like have the first person enter something than have the second set of objects take the place of the first when a new set of information is to be inputted. Secondly, how do you find the amount of digits in a variable/object? I might have more questions so please help me out.
 
- You need the clarifiy what you mean by the first question.
- For getting the number of digits, if the variable is a string, then just use strlen(), else the easiest way is to use a function like this:

// For positive integers only.
int CountDigits(int number)
{
int count = 0;
while(true)
{
number = number / 10;
count++;

if(number == 0)
return count;
}

}
 
Okay, I have a structure that has 5 things, char lname, char fname, int idnumber, int pay, int hours. I have a function where you call that and later on the user enters whether they want to run the program again so the function that uses the structure has to change its object to be inputted in. Like the first time they enter stuff it's cin>>objEmp1.lname; but you can't change that. I hope you see what I mean.
 
Originally posted by: idNut
Okay, I have a structure that has 5 things, char lname, char fname, int idnumber, int pay, int hours. I have a function where you call that and later on the user enters whether they want to run the program again so the function that uses the structure has to change its object to be inputted in. Like the first time they enter stuff it's cin>>objEmp1.lname; but you can't change that. I hope you see what I mean.

I really don't. Consider this code fragment:

struct input
{
char strName[50];
int number;
};


void GetInput(input &in)
{
cout << "Name: ";
cin >> in.strName;

cout << "Number: ";
cin >> in.number;
}

void main()
{
input user_input;
GetInput(user_input);
GetInput(user_input);
GetInput(user_input);
}


What exactly do you mean by re-using?
 
Back
Top