#include <iostream>

using std::cout;
using std::cin;
using std::endl;

void Calculate( double );

int main()
{
       int worked;
       double salary;
       double pay;
       
       
       cout << "Enter the hours worked: (-1 to end)" << endl;
       cin >> worked;
       cout << "Enter the salary: " << endl;
       cin >> salary;
       
       while( worked > 0 ){
              Calculate( );
              
              cout << "Enter the hours worked: (-1 to end)" << endl;
              cin >> worked;
              cout << "Enter the salary: " << endl;
              cin >> salary;
              }
              
       system("pause");
       return(0);
}

void Calculate( double )
{
     double over;
     double half;
     double extra;
     double pay;
     int worked;
     double salary;
     
     if(worked > 40){
               over = worked - 40;
               half = salary * 1.5;
               extra = over * half;
               pay = (worked * salary) + extra;
               
               cout << "The pay is: " << "$" << pay << endl;
               }
               
     else
               pay = worked * salary;
               
               cout << "The pay is: " << "$" << pay << endl;
               
}

Ok, finally fixed the code tags. =P

Ancient Dragon commented: Good job -- You finally got code tags right :) +36

Recommended Answers

All 10 Replies

You are not passing any thing to the calculate function within main.So few parameters error.

void Calculate( double )

Don't know what exactly you want to do with this really :?: If you want to pass any parameters then pass it else make the function as

void Calculate()

in both the initialization and declaration.

Yeah, that's the error I'm getting, I know...but I'm not sure how to fix that...I'm totally new to C++ and I really don't understand it... How do I pass something to the function or from it?

The reason I put "void Calculate( double )" was because I was trying to model it from my text book, but I obviously didn't do it right...

Does the parameter need to be the variables I'm working with inside of it? Because I tried doing that, but it didnt work either...

pass to function: its just a parameter

int foo(int n)
{
    return n*10;
}

int main()
{
   // This line passes the value 15 to the function foo()
   // and gets the return value in the variable named x
    int x = foo(15);
}

Yeah, that's the error I'm getting, I know...but I'm not sure how to fix that...I'm totally new to C++ and I really don't understand it... How do I pass something to the function or from it?

1>First decide what the Calculate function needs to do.
2>Now decide whether you want any inputs from main to calculate within the calculate function.
3>If so pass those variables as parameters properly.
4>If not make both the functions as returning void.Simple right ??? :)
5>Now try it.Don't worry we are here to help.

Here is something you can read from. <link>

line 34 of the code you posted: In the actual function you have to give the parameter a name, such as void Calculate( double number )

Sorry for the double post....

OK, hold on. I added a type to the function, which I didn't know it needed until I read Ancient Dragon's post, and now it doesn't give me any errors, but it doesn't display the result of Calculate. Is that because double pay isn't part of the parameters?

Here's my code:

#include <iostream>

using std::cout;
using std::cin;
using std::endl;

double Calculate( int worked, double salary );

int main()
{
       int worked;
       double salary;
       double pay;
       
       
       cout << "Enter the hours worked: (-1 to end)" << endl;
       cin >> worked;
       cout << "Enter the salary: " << endl;
       cin >> salary;
       
       while( worked > 0 ){
             double Calculate( int worked, double salary );
              
              cout << "Enter the hours worked: (-1 to end)" << endl;
              cin >> worked;
              cout << "Enter the salary: " << endl;
              cin >> salary;
              }
              
       system("pause");
       return(0);
}

 double Calculate( int worked, double salary )
{
     double over;
     double half;
     double extra;
     double pay;

     
     if(worked > 40){
               over = worked - 40;
               half = salary * 1.5;
               extra = over * half;
               pay = (worked * salary) + extra;
               
               cout << "The pay is: " << "$" << pay << endl;
               }
               
     else
               pay = worked * salary;
               
               cout << "The pay is: " << "$" << pay << endl;
               
               return( pay );
               
}

Look you advanced so much. Read the link in that post its quite informative for beginners.Go on you are doing great. :)

Alright, I have read most of that post...I believe that the values need to be passed by reference...which would change the values...but does that mean that that is the only thing that I can return? When the program runs, it just completely skips the whole...display the results thing. Does it need another pause maybe? Let me go mess with it a bit more and I'll report back. Thank you so much for your help! This is really helping me learn, not just get it done, and I'm grateful for that =)


EDIT:

Hmm...I really am not sure what I need to change in the program to make it transfer the results and display them properly within that one function. I can't use another function, because a) that would just add to the confusion, and b) I would get points off the assignment for not doing it precisely as directed. I'm going to go back an reread that link again and see if I can make anything click...

Alright, I have read most of that post...I believe that the values need to be passed by reference...which would change the values...but does that mean that that is the only thing that I can return? When the program runs, it just completely skips the whole...display the results thing. Does it need another pause maybe? Let me go mess with it a bit more and I'll report back. Thank you so much for your help! This is really helping me learn, not just get it done, and I'm grateful for that =)

Hey buddy I wasn't boasting about my post.There is something like <link> in that post (#5) click that and you will get a page which contains all the information you need for this problem.Have a good scan through it.You will learn a lot.:)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.