1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

I have 102 Errors, may i know why it is this case?

Discussion in 'C++' started by won212, Apr 5, 2012.

  1. won212

    won212 New Member

    Joined:
    Mar 3, 2012
    Messages:
    17
    Likes Received:
    2
    Trophy Points:
    0
    I have 102 Errors, may i know why it is this case? :O
    Any solution to this?

    Code:
     
    #include<stdio.h>
    #include<iostream>
    #define MAX 30
    using namespace std;
    typedef struct pqueue
    {
        char str[MAX];
    int priority; 
    pqueue* next;
    }pqueue;
    int enqueuepriority(pqueue *&pq, char str[MAX], int priority)
    {
        if(priority>0)
    {
    pqueue *p=(pqueue*)malloc(sizeof(pqueue));
    for(int i=0;i<MAX;i++)
    p->str[i]=str[i];
        p->priority=priority;
        p->next=pq->next;
        pq->next=p;
        return 1;
    }
    else return 0;
    }
    char* dequeue(pqueue *&pq)
    {
    pqueue *p;
    if(pq->next!=NULL)
    {
        p=pq->next;
    pq->next=pq->next->next;
    return p->str;
    }
    else return "";
    }
    
    int main()
    {
    cout<<"(1) Enqueue (single)"<<endl;
    cout<<"(2) Enqueue (multiple)"<<endl;
    cout<<"(3) Dequeue (single)"<<endl;
    cout<<"(4) Dequeue (all)"<<endl;
    cout<<"(5) Quit"<<endl;
    int re=0,t=1;
        static char* str=new char[MAX];
    int priority=0;
    pqueue *pq=(pqueue*)malloc(sizeof(pqueue));
    pq->next=NULL;
    while(re!=5)
    {
    cout<<"Choose an action:";
    cin>>re;
    switch(re)
    {
    case 1:
    cout<<"Enter a name to save and its priority"<<endl;
                scanf("%s%d",str,&priority);
                if(enqueuepriority(pq,str,priority)) 
    break;
    else
    {
    cout<<"INPUT ERROR!!"<<endl;
    break;
    }
    case 2:
    cout<<"Enter names to save and their priority. Enter “done” to quit"<<endl;
    do
    {
        scanf("%s",str); 
    if(strcmp(str,"done")!=0)
    {
                            scanf("%d",&priority);
                            enqueuepriority(pq,str,priority);  
    }
    else t=0;
    
    }while(t==1);
    break;
    case 3:
    str=dequeue(pq);
    if(str=="")
    cout<<"NULL"<<endl;
    else
    printf("%s\n",str);
    break;
    case 4:
    while(pq->next!=NULL)
    {
    
    printf("%s\n",dequeue(pq));
    }   
    break;
    case 5: break;
    default:
    cout<<"INPUT ERROR!!"<<endl;
    break;
    }
             
    }
    delete  [] str;
    return 0;
    } 
    
     
  2. peermhd

    peermhd New Member

    Joined:
    Apr 5, 2012
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    Re: I have 102 Errors, may i know why it is this case? Try this, its running

    Code:
    #include<stdio.h>
    #include<iostream.h>
    #include<stdlib.h>
    #include<string.h>
    #define MAX 30
    typedef struct pqueue
    {
    	 char str[MAX];
    int priority;
    pqueue* next;
    }pqueue;
    int enqueuepriority(pqueue *&pq, char str[MAX], int priority)
    {
    	 if(priority>0)
    {
    pqueue *p=(pqueue*)malloc(sizeof(pqueue));
    for(int i=0;i<MAX;i++)
    p->str[i]=str[i];
    	 p->priority=priority;
    	 p->next=pq->next;
    	 pq->next=p;
    	 return 1;
    }
    else return 0;
    }
    char* dequeue(pqueue *&pq)
    {
    pqueue *p;
    if(pq->next!=NULL)
    {
    	 p=pq->next;
    pq->next=pq->next->next;
    return p->str;
    }
    else return "";
    }
    
    int main()
    {
    cout<<"(1) Enqueue (single)"<<endl;
    cout<<"(2) Enqueue (multiple)"<<endl;
    cout<<"(3) Dequeue (single)"<<endl;
    cout<<"(4) Dequeue (all)"<<endl;
    cout<<"(5) Quit"<<endl;
    int re=0,t=1;
    	 static char* str=new char[MAX];
    int priority=0;
    pqueue *pq=(pqueue*)malloc(sizeof(pqueue));
    pq->next=NULL;
    while(re!=5)
    {
    cout<<"Choose an action:";
    cin>>re;
    switch(re)
    {
    case 1:
    cout<<"Enter a name to save and its priority"<<endl;
    				scanf("%s%d",str,&priority);
                if(enqueuepriority(pq,str,priority)) 
    break;
    else
    {
    cout<<"INPUT ERROR!!"<<endl;
    break;
    }
    case 2:
    cout<<"Enter names to save and their priority. Enter “done” to quit"<<endl;
    do
    {
    	 scanf("%s",str);
    if(strcmp(str,"done")!=0)
    {
                            scanf("%d",&priority);
    								enqueuepriority(pq,str,priority);
    }
    else t=0;
    
    }while(t==1);
    break;
    case 3:
    str=dequeue(pq);
    if(str=="")
    cout<<"NULL"<<endl;
    else
    printf("%s\n",str);
    break;
    case 4:
    while(pq->next!=NULL)
    {
    
    printf("%s\n",dequeue(pq));
    }
    break;
    case 5: break;
    default:
    cout<<"INPUT ERROR!!"<<endl;
    break;
    }
             
    }
    delete  [] str;
    return 0;
    }
     
    Last edited by a moderator: Apr 5, 2012
  3. won212

    won212 New Member

    Joined:
    Mar 3, 2012
    Messages:
    17
    Likes Received:
    2
    Trophy Points:
    0
    Re: I have 102 Errors, may i know why it is this case? Try this, its running

    Hi expert, thanks for the amendment!
    Would like to ask i got the error is it because i did not specify #include<string.h>?
    However when i tried to preview your code, I got error like "Error 1 error C1083: Cannot open include file: 'iostream.h': No such file or directory"? & " 2 IntelliSense: cannot open source file "iostream.h"?

     
  4. won212

    won212 New Member

    Joined:
    Mar 3, 2012
    Messages:
    17
    Likes Received:
    2
    Trophy Points:
    0
    Re: I have 102 Errors, may i know why it is this case? Try this, its running

    Hi, thanks for the posting however, I got error like "Error1:error C1083: Cannot open include file: 'iostream.h':"
     

Share This Page