Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

dll

Posted on 2004-09-28
5
Medium Priority
?
283 Views
Last Modified: 2010-04-01
hi
 experts

    i have a runtime error in my program in c++.it is a very small program but not able to debug it.there is the source code.

#include <iostream>
using namespace std;
int insert();
int print();
main()
{
   struct node
   {
         int info;
         node *next;
   };

      node* head=NULL;
      node* temp=NULL;
      node* temp1=NULL;
      head=new node;
      head->next=NULL;
      int c;
      cout<<"1--->insert."<<endl<<"2--->delete."<<endl<<"3--->print."<<endl<<"4--->Exit."<<endl;
      cout<<"Enter the choice --";
      cin>>c;
      switch(c)
      {
      case 1:insert();
            {
              int x;
            cout<<"Enter the data to be insterted __ ";
              cin>>x;
              if(head->next==NULL)
                head->info=x;
              else
                  {
                  temp=head;
                  while(temp->next!=NULL)
                    temp=temp->next;
                  if(temp->next==NULL)
                    {
                     temp1=new node;
               temp1->info=x;
                     temp->next=temp1;
                     temp1->next=NULL;
                    }
                  }
            }
            break;
//      case 2:del();break;
    case 3:print();
            {
      if(head==NULL)
            cout<<"No elements to display";
      else
      {
      temp=head;
       do
         {
               cout<<temp->info<<"->";
               temp=temp->next;
         }while(temp->next!=NULL);
         }
}
break;
      case 4:exit(0);break;
      default:cout<<"Entered wrong choice";
      }
      return 0;
}
 

please help me asap.
0
Comment
Question by:rajashekar2004
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 

Accepted Solution

by:
amjedmsa earned 80 total points
ID: 12177039
why int insert();

here a modifiyed one it works

#include <iostream>

using namespace std;


int insert;
int print;
main()
{
   struct node
   {
        int info;
        node *next;
   };

     node* head=NULL;
     node* temp=NULL;
     node* temp1=NULL;
     head=new node;
     head->next=NULL;
     int c;
     cout<<"1--->insert."<<endl<<"2--->delete."<<endl<<"3--->print."<<endl<<"4--->Exit."<<endl;
     cout<<"Enter the choice --";
     cin>>c;
     switch(c)
     {
     case 1:insert;
          {
             int x;
            cout<<"Enter the data to be insterted __ ";
             cin>>x;
             if(head->next==NULL)
              head->info=x;
             else
               {
                temp=head;
                while(temp->next!=NULL)
                 temp=temp->next;
                if(temp->next==NULL)
                 {
                  temp1=new node;
               temp1->info=x;
                  temp->next=temp1;
                  temp1->next=NULL;
                 }
               }
          }
          break;
//     case 2:del();break;
    case 3:print;
          {
     if(head==NULL)
          cout<<"No elements to display";
     else
     {
      temp=head;
       do
        {
             cout<<temp->info<<"->";
             temp=temp->next;
        }while(temp->next!=NULL);
        }
}
break;
     case 4:exit(0);break;
     default:cout<<"Entered wrong choice";
     }
     return 0;
}
0
 
LVL 39

Expert Comment

by:itsmeandnobodyelse
ID: 12177675
Maybe you want that:

#include <iostream>
using namespace std;

struct node
{
   int info;
   node *next;
};

void insert(node*& head);
void print(node* head);
void deleteAll(node* head);

int main()
{
   
    node* head= NULL;
   
    while (true)
    {
        int c;
        cout<<endl<<"1--->insert."<<endl<<"2--->delete."<<endl<<"3--->print."<<endl<<"4--->Exit."<<endl;
        cout<<"Enter the choice --";
        cin>>c;
       
        switch(c)
        {
        case 1:
            insert(head);
            break;
            //     case 2:del();break;
        case 3:
            print(head);
            break;
        case 4:
            deleteAll(head);
            return 0;
        default:
            cout<<"Entered wrong choice"<<endl;
            break;
        }
    }
    return 1;
}


void insert(node*& head)
{  
    node* temp;
    node* temp1;
    int x;
    cout<<"Enter the data to be inserted __ ";
    cin>>x;
    if(head==NULL)
    {
        head = new node;
        head->next = NULL;
        head->info = x;
        return;
    }
    temp=head;
    while(temp->next!=NULL)
        temp=temp->next;
    temp1=new node;
    temp1->info=x;
    temp->next=temp1;
    temp1->next=NULL;
}

void print(node* head)
{
    if(head==NULL)
        cout<<"No elements to display";
    else
    {
        node* temp=head;
        do
        {
            cout<<temp->info<<"->";
            temp=temp->next;
        }
        while(temp !=NULL);
    }
}


void deleteAll(node* head)
{
    node* temp = head;
    node* temp1;
   
    while (temp != NULL)
    {
        temp1 = temp->next;
        delete temp;
        temp = temp1;
    }
}

Regards, Alex
0

Featured Post

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Article by: evilrix
Looking for a way to avoid searching through large data sets for data that doesn't exist? A Bloom Filter might be what you need. This data structure is a probabilistic filter that allows you to avoid unnecessary searches when you know the data defin…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
Suggested Courses

604 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question