problrm

Aug 15, 2012 at 8:54pm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include <iostream>
using namespace std;

struct list
{
    int data;
    list *next;
};

list *node, *tail = NULL, *head = NULL;
void add2list();
void extrem();

int main()
{
    add2list();
    extrem();

    return 0;
}

void add2list()
{
    int input;
    cout << "Adding values to list :\n";
    cout << ">>";

    while(cin >> input)
    {
        node = new list;
        node->data = input;
        node->next = NULL;

        if (head == NULL)
        {
            head = node;
            tail = node;
        }
        else
         {
            tail->next = node;
            tail = node;
         }
    cout << ">>";
    }
}

void extrem()
{
   int x, y;
   cin >> x >> y;
}


Why doesn't the implementation of the instructions that in the function extrem???
help me to solve this problema
Last edited on Aug 15, 2012 at 8:55pm
Aug 15, 2012 at 9:05pm
Why doesn't the implementation of the instructions that in the function extrem???


This makes no sense.

What do you want the function extrem to do? Right now, it create two variables, gets values for them from the user, and then destroys those variables as it ends. It seems pretty useless.
Aug 15, 2012 at 9:24pm
when i run this program it's only execute the add2list function ????

is it clear now or not?
Last edited on Aug 15, 2012 at 9:25pm
Aug 15, 2012 at 9:36pm
1
2
3
4
while(cin >> input)
{
  //  This loops until != cin.good()
}


The cin object is broken by the time it reaches extrem. Put cin.clear() @line 46

Aug 15, 2012 at 9:45pm
@LowestOne

I did like what you said but the problem not solved yet
Aug 15, 2012 at 10:14pm
I think the program does not take any input, only in extrem(), which is called after add2list().
Aug 16, 2012 at 1:37am
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
void add2list()
{
    int input;
    cout << "Adding values to list :\n";
    cout << ">>";

    while(cin >> input)
    {
        node = new list;
        node->data = input;
        node->next = NULL;

        if (head == NULL)
        {
            head = node;
            tail = node;
        }
        else
         {
            tail->next = node;
            tail = node;
         }
    cout << ">>";
    }
cin.clear();
cin.ignore();
}


by adding
1
2
cin.clear();
    cin.ignore();

@last line
Topic archived. No new replies allowed.