I need help with this program
Whenever I compile it I can run it and enter the name of the employee and the first price but then it just jumps to the other two after that. Also how would I declare this in an array for 10 customers to display 10 customers names and their data? Thanks for the help
Line 34: when you use >> to read a string, the program will stop reading when it gets to any white space. So if you enter "Donald Trump", it will read "Donald" into the string and leave "Trump" in the stream. Use getline() instead to read the entire line: getline(cin, customer.name);
Line 37: You prompt for the TV cost, but you don't read it.
Also how would I declare this in an array for 10 customers
Start with a small change: pass the customer instance that you want to read into billing(). Then declare the customerBundles object inside main and pass it to billing(). This makes the program a lot more flexible:
So when I do that it compiles and runs but my second value is turned into scientific notation I guess? So how do I fix that?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
void billing()
{
customerBundles customer;
cout<<"What are the names of the customers? "<<endl;
getline(cin, customer.name);
cout<<"What value will this customer pay for internet? "<<endl;
cin>>customer.internet;
cout<<"What about TV? "<<endl;
cin>>customer.television;
cout<<"How much for voice? "<<endl;
cin>>customer.television;
cout<<customer.name<<"\n"<<customer.internet<<"\n";
cout<<customer.voice<<"\n"<<customer.television<<"\n"<<endl;
cout<<"Monthly total:"<<customer.voice+customer.television+customer.internet;
cout<<endl;
}
What are the names of the customers?
Kody
What value will this customer pay for internet?
25
What about TV?
15
How much for voice?
35
Kody
25
2.10169e-317
35
Monthly total: 60
Your for loop runs 10 times, but the code within it reads into the same customer object each time.
The point of adding the customer parameter to billing() is that it lets main call billing to read any customer that main wants. So you want the array and the for loop in main(), not in billing().