lundi 22 juin 2015

No match for 'operator*' error

Hello fellow programmers!

I was going to write a small program for calculating total pay for different periods of time depending on the amount of hours and the salary that the user enters. I managed to make a small bit of the program but when I try to run it and test it I get the following error:

Line 33: error: no match for 'operator*' in 'pay * hours_day'

I tried doing a google search on this problem but I am really confused on what causes it.

here is my full program code:

#include <iostream>
#include <random>
#include <time.h>
#include <cstdlib>
#include <string>

using namespace std;

/*

*Program Flowchart*

- Find out how much a worker gets paid per hour, and then find out how many hours they work
a day, and then multiply that to get the total pay in a week or a month or a year.

*/

// global variables

string pay;
float hours_day;


// function that takes the amount of money and calculates the total pay in a week
int total_pay_week() {
    cout << "Type in your salary per hour." << endl;
    cin >> pay;
    cout << "Ok, how many days do you work per day?" << endl;
    cin >> hours_day;

    float total_day = pay * hours_day;

    float total_week = total_day * 7;

    cout << "Your total pay in a week is " << total_week << "if you worked " << hours_day << " per day. " << endl;

}


int main() {

    total_pay_week();

}

This is a very early version of my program! I just wanted to know what causes this problem.

Aucun commentaire:

Enregistrer un commentaire