Hello! I'm a new female coder and I have started getting Computer science assignments but do not fully understand some of them. Can someone please help me with this assignment and how I would lay it out and everything? thank you!
"Write a program with a function that uses local variables in the function to calculate how much money you will earn for working a certain number of hours a week at a particular rate per hour. Prompt the user to enter the hours worked and rate of pay."
This is c++ and we have just started using functions. I have completely been lost since then.
/*
"Write a program with a function that uses local variables in the function to
calculate how much money you will earn for working a certain number of hours a
week at a particular rate per hour. Prompt the user to enter the hours worked
and rate of pay."
*/
#include <iostream>
double calc_pay()
{
int num_hours = 0;
double hourly_rate = 0.0;
// TODO
// Read the user input, do calculation and return result
}
int main()
{
std::cout<< "Welcome at the Pay Calculator\n";
calc_pay();
}
What part are you having problems with? Can you prompt the user and obtain the inputs? Can you perform the calculation from the inputs? If you didn't have to use a function, could you then code the program? Post your current code.
@thmm: You wrote a function that returns a value, yet you use (call) it without making use of the returned value. That (line 22) is not good for educational purposes.
Doesn't modern C++ have an (optional) "Thou shalt not ignore the value I give!" attribute for functions?
@thmm helpful suggestion is OK. Maybe the question is OK too and parameter passing comes later in @OP's burgeoning career in coding. Taken all back now because I missed the double.