Write a main function and the function it calls with three array arguments (Name
ID: 3772812 • Letter: W
Question
Write a main function and the function it calls with three array arguments (Name, Wage, and Hours) and returns count. The function that is called will ask a user to input the values for the three variables and put them in the arrays Name, Wage, and Hours and then print the content of these variables out to the screen when you return to main. The loop stops if the user does not want to enter more data.
You must keep track of how many times you asked the user to input these values. When you return to main print using cout the values of Count and the arrays Name, Wage, Hours.
Explanation / Answer
#include <iostream>
using namespace std;
int getData();
int main() {
ios::sync_with_stdio(false);
int count = getData();
cout << "Count: " << count;
}
int getData() {
int count = 0;
char Name[15], Wage[15], Hours[15];
char response;
while (true) {
cout << "Enter y to continue and n to exit ";
cin >> response;
if (response == 'y') {
cout << "Enter Name ";
cin >> Name;
cout << "Enter Wage ";
cin >> Wage;
cout << "Enter Hours ";
cin >> Hours;
count++;
cout << "Name: " << Name << " Wage: " << Wage << " Hours: " << Hours << endl;
}
else
break;
}
return count;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.