0

I am trying to make a program for my 'operation research' class. I have written code that works like a flowchart for a single server queuing system.

I am getting multiple errors (which seem simple), but I can’t figure out how to fix them. Some examples are 'missing terminating character', 'stray', and 'not declared in this scope'. How can I fix them?

#include <iostream>
#include <cmath>
using namespace std;

const int BUSY = 1;
const int IDLE = 0;

int
    choice,
    WL,
    SS;

double
    MX,
    IT,
    ST,
    TM,
    AT,
    DT,
    TypeOfEvent,
    NextServiceTime,
    ProgressAT’
    ProgressDT;


void  initialize();
void  Timing();
void  Arrival();
void  Departure();
float expon(float mean);

int main()
{
    initialize();
    do
    {
        cout<<"Enter your Policy: ";
        cin>>choice;
    }
    while(choice>2 || choice<1);

    cout << "'End of Simulation’ Time: " << MX << endll;

    while(true)
    {
        Timing();   // To determine the next event

        if(TM > MX)
            break;

        switch (int(TypeOfEvent))
        {
            case 1:
                Arrival();
                break;

            case 2:
                Departure();
                break;
        }
    }
    return 0;
}

void initialize()
{
    IT = 1.0;
    ST = 0.5;
    TM = 0.0;
    SS = IDLE;
    WL = 0;
    AT = TM + expon(IT);          // Arriving
    NextServiceTime = expon(ST);
    DT = 1.0e+10;                 // Guaranteeing that the first 
                                  // event is arriving
    ProgressAT = 0.0;
    ProgressDT = 0.0;
}

void Timing()
{
    TypeOfEvent = 0;

    if(AT < DT)
    {
        TypeOfEvent = 1;
        TM = AT;
    }
    else
    {
        TypeOfEvent = 2;
        TM = DT;
    }

    if (TypeOfEvent == 0)
    {
        cout << "System Idle " << TM;
        exit(1);
    }
}

void Arrival()
{
    if (SS == BUSY)
    {
        ++WL;
        ServiceTime[WL] = NextServiceTime;
    }
    else
    {
        SS = IDLE;
        DT = TM + NextServiceTime;
    }

    AT = TM + expon(IT);
    NextServiceTime = expon(ST);
}

void Departure()
{
    if (WL == 0)
    {
        SS = IDLE;
        DT = 9999;
    }
    else
    {
        if(choice == 2)
        {
            DT = TM + NextServiceTime;
        }
        --WL;
    }
}
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
HSA
  • 1
  • 3
  • 1
    it would be helpful to point out which lines the errors occur on – Slepz Dec 31 '15 at 21:09
  • 1
    `double....ProgressAT’` That's a single quote, should be a comma. `endll` should be `endl`. Learn to decode the compiler's warnings and errors. Also, make sure they are all enabled. – 001 Dec 31 '15 at 21:13
  • 1
    Start with the smallest piece of code that compiles, even if its only `int main(){}`, then keep adding to it, making sure that after each addition the code keeps compiling. Otherwise you may run into a mess (especially when a beginner). – vsoftco Dec 31 '15 at 21:15
  • you have an amibiguous IF in your department() function. You should add curly braces even if you only want the following line in them. It's good practice for preventing future errors – Slepz Dec 31 '15 at 21:21
  • Your `MX` variable is not initialized before it is printed. It is never assigned a value. I **strongly** recommend you initialize your variables before you use them. – Thomas Matthews Dec 31 '15 at 22:54
  • 1
    I recommend not using abbreviations as variable names. Variable name length has no impact on a program's performance (they disappear during compilation). So make your code more readable and spell them out. Otherwise, take a keyboarding class. – Thomas Matthews Dec 31 '15 at 22:56
  • Why is `TypeOfEvent` a floating point value? It only gets assigned integer values. You even cast it to an integer for the `switch` statement. – Thomas Matthews Dec 31 '15 at 22:57
  • Where is the `exponen` function? Is there a reason for it to use floating point? I'm trying to find the reason you are using floating point in your program. – Thomas Matthews Dec 31 '15 at 22:59
  • I have fixed many of what you guys have caught. Thank you for that! The only error I have now is that nearly every variable was not declared in the scope. I have read about this problem on other stackoverflow posts, but I still cant seem to understand where I went wrong. Isn't it enought to declare them once at the beginning? I'm thick, I know. If someone could point out where I need to declare my variables, I would be very grateful. – HSA Jan 01 '16 at 15:54
  • @Slepz Thank you for your help. – HSA Jan 01 '16 at 16:10
  • @ThomasMatthews , I am using abrreviations to make the code have the same naming system as we are using in class. But I understand what you are saying. I also realized that i didnt need to make TypeOfEvent a floating point, so I have corrected that mistake. I was trying to use the floating and double variables because many of my variables are actually representative of time units, so I wanted there to be a higher accuracy. Thanks for your help. – HSA Jan 01 '16 at 16:41
  • @JohnnyMopp, Thank you for your help. – HSA Jan 01 '16 at 16:41
  • The stray errors are probably caused by the two instances of Unicode code point U+2019 ([RIGHT SINGLE QUOTATION MARK](https://www.utf8-chartable.de/unicode-utf8-table.pl?start=8212&number=128))—at least as posted here. Near "ProgressAT" (line 23). The other one is inside a string and may be accepted (near "End of Simulation", line 42). The first one would cause a triplet of stray errors (starting with something like `someFile.c:23: error: stray ‘\342’ in program`): 342 200 231 (octal) → 0xE2 0x80 0x98 (hexadecimal) → UTF-8 sequence for U+2019. – Peter Mortensen May 25 '23 at 09:18
  • cont' - There aren't any other stray characters of [the common ones](https://pmortensen.eu/world2/2023/05/01/unicode-blues-in-c-and-similar-languages-after-copying-from-web-pages-skype-chat-etc/) than U+2019. – Peter Mortensen May 25 '23 at 09:22
  • U+2019 can be searched (and replaced) for by using the regular expression `\x{2019}` in any modern text editor or IDE. Note: The notation is different in Visual Studio Code (and probably others): `\u2019` (instead of `x{2019}`) – Peter Mortensen May 25 '23 at 09:22
  • 1
    There are multiple errors here, but for the stray characters, this is a ***very*** common error when copying code from web pages, [PDF](https://en.wikipedia.org/wiki/Portable_Document_Format) documents, through chat (e.g. [Skype Chat](https://en.wikipedia.org/wiki/Features_of_Skype#Skype_chat) or [Facebook Messenger](https://en.wikipedia.org/wiki/Facebook_Messenger)), etc. The canonical question is *[Compilation error: stray ‘\302’ in program, etc.](https://stackoverflow.com/questions/19198332)*. – Peter Mortensen May 25 '23 at 09:38

0 Answers0