0

HELP please. I'm new to this so please be nice and descriptive. I coded this in Visual studio and the goal is to find out how many of each L, M, and S trays I need based on the number of people attending. I am trying to divide by remainder and I'm getting an error on the last two lines. "expression must have integral or unscoped enum type" --- I don't even know what that means. English, please?

#include <iostream>
#include <iomanip>
#include <cmath>

using namespace std;

int main()
{


//prompt user
    cout << "Please enter number of guests attending event:";
    double attendees;
    cin >> attendees;

    double large_trays = attendees / 7;

    double medium_trays = large_trays % 3;

    double small_trays = medium_trays % 1;
h20Pohlow
  • 15
  • 4

2 Answers2

0

The problem is that you are using a 'double' type variable. However the modulo operator is only available for integer type variables like 'int'.

Either use 'int' instead of 'double' or use type casting.

double medium_trays = (int)large_trays % 3;
Shaana
  • 326
  • 1
  • 5
0

This exception is being thrown because you are trying to use the modulus arithmetic operator '%' on a non-integer. See this question: Why does modulus division (%) only work with integers?

Try this:

double large_trays = attendees / 7;

int large_trays_rounded = (int)large_trays;

int medium_trays = large_trays_rounded % 3;

int small_trays = medium_trays % 1;
Community
  • 1
  • 1
brirus
  • 81
  • 6