0

Well guys , i have a problem , i have got my linked list , it add numbers (to the list) , and show numbers(from the list ) , but i can´t add the numbers of the list , i really need help , if the list would be:
1) 23 , 2) 24 , 3) 25 .... the addition must be : 1) 23 , 2) (23+24)=47 (just showing 47) , 3)(47+25)=70 (just showing 70)

      #include <iostream>
        #include <stdio.h>
        #include <stdlib.h>


    using namespace std;

    struct nodo{
           int nro;
           struct nodo *sgte;
    };

    typedef struct nodo *Tlista;

    void insertarInicio(Tlista &lista, int valor)
    {
        Tlista t, q = new(struct nodo);

        q->nro  = valor;
        q->sgte = NULL;

        if(lista==NULL)
        {
            lista = q;
        }
        else
        {
            t = lista;
            while(t->sgte!=NULL)
            {
                t = t->sgte;
            }
            t->sgte = q;
        }

    }
    void mostrarLista(Tlista lista)
    {
         int i = 0;

         while(lista != NULL)
         {
              cout <<' '<< i+1 <<") " << lista->nro << endl;
              lista = lista->sgte;
              i++;
         }
    }
    void menu1()
    {
        cout<<"\t\t\t            FIFO            "<<endl;
        cout<<"\t\t_______________________________________\n"<<endl;
        cout<<"\t\t\t 1. REGISTER TIMES              "<<endl;
        cout<<"\t\t\t 2. SHOW LIST            "<<endl;
        cout<<"\t\t\t 3. SOLVE METHOD                  "<<endl;
        cout<<"\t\t\t 4. EXIT                            "<<endl;
        cout<<"\t\t_______________________________________\n"<<endl;
        cout<<"\t\t\t CHOOSE AN OPTION: ";
    }

    void fifo(Tlista lista)
    {
        //HERE MUST BE THE CODE TO ADD THE LIST NUMBERS 
    }

    /*                        principal function
    ---------------------------------------------------------------------*/

    int main()
    {
        Tlista lista = NULL;
        int op;     //menu option
        int _dato;  // number to add

        system("color 0b");

        do
        {
            menu1();  cin>> op;

            switch(op)
            {
                case 1:

                     cout<< "\n TIME OF PROCCESS : "; cin>> _dato;
                     insertarInicio(lista, _dato);
                break;

                case 2:

                     cout << "\n\n SHOWING LIST\n\n";
                     mostrarLista(lista);
                break;

               case 3:

                     cout << "\n\n SOLVED \n\n";
                     fifo(lista);
                break;


            }

            cout<<endl<<endl;
            system("pause");  system("cls");

        }while(op!=4);

        system("pause");
        return 0;
    }
2
Contributors
1
Reply
9
Views
2 Years
Discussion Span
Last Post by Taywin
0

You simply add a sum variable inside your mostrarLista() and keep adding it. Display the variable instead of the value inside your node. Does that make sense?

PS: Next time, please show your sample output, so that people do not need to dig into your code in order to understand the issue.

Edited by Taywin

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.