#include<iostream>
#include<string>
usingnamespace std;
class Node
{
public:
int value;
Node * next;
Node();
Node(int);
};
Node::Node():value(0),next(NULL){}
Node::Node(int v):value(v),next(NULL){}
void Print(Node* h)
{
while(h)
{
cout<<" -> "<<h -> value;
h = h -> next;
}
cout<<endl;
}
void Create(Node *& head, int n)
{
head = new Node(1);
Node * tmp = head;
string s; char c;
cin>>s;
s="";
for(int i =0; i < s.length; i++)
c = s.charat(i);
char v = c = '0';
}
void DeleteAll(Node*& head)
{
Node* tmp;
while(head)
{
tmp = head;
head = head->next;
delete tmp;
}
}
int main()
{
char operation;
int result;
Node * h1 = NULL;
Node * h2 = NULL;
cout<<"Enter first number:";
Create(h1);
cout<<endl;
cout<<"Enter second number";
Create(h2);
cout<<endl;
cout<<"What operation you want, + ot -";
cin>>operation;
if( operation == '+' )
{
result = h1 + h2;
cout<<"Result="<<result<<endl;
}
elseif( operation == '-' )
{
result = h1 - h2;
cout<<"Result="<<result<<endl;
}
}
This is as far as I could get without completely altering your code. Here are the errors:
---- In function `void Create(Node*&, int)':
34 invalid use of member (did you forget the `&' ?)
35 'struct std::string' has no member named 'charat'
---- In function `int main()':
28 too few arguments to function `void Create(Node*&, int)'
59 at this point in file
28 too few arguments to function `void Create(Node*&, int)'
62 at this point in file
69 invalid operands of types `Node*' and `Node*' to binary `operator+'
#include<iostream>
#include<string>
usingnamespace std;
class Node
{
public:
int value;
Node * next;
Node();
Node(int);
};
Node::Node():value(0),next(NULL){}
Node::Node(int v):value(v),next(NULL){}
void Print(Node* h)
{
while(h)
{
cout<<" -> "<<h -> value;
h = h -> next;
}
cout<<endl;
}
void Create(Node *& head, int n)
{
head = new Node(1);
Node * tmp = head;
string s; char c;
cin>>s;
s="";
for(int i =0; i < s.length(); i++)
c = s.at(i);
char v = c = '0';
}
void DeleteAll(Node*& head)
{
Node* tmp;
while(head)
{
tmp = head;
head = head->next;
delete tmp;
}
}
int main()
{
char operation;
int result;
Node * h1 = NULL;
Node * h2 = NULL;
cout<<"Enter first number:";
Create(h1);
cout<<endl;
cout<<"Enter second number";
Create(h2);
cout<<endl;
cout<<"What operation you want, + ot -";
cin>>operation;
if( operation == '+' )
{
result = h1 ->value + h2 ->value;
cout<<"Result="<<result<<endl;
}
elseif( operation == '-' )
{
result = h1 ->value - h2 ->value;
cout<<"Result="<<result<<endl;
}
}
the errors:
1>c:\users\documents\visual studio 2010\projects\project\project\1.cpp(34): warning C4018: '<' : signed/unsigned mismatch
1>c:\users\documents\visual studio 2010\projects\project\project\1.cpp(59): error C2660: 'Create' : function does not take 1 arguments
1>c:\users\documents\visual studio 2010\projects\project\project\1.cpp(62): error C2660: 'Create' : function does not take 1 arguments
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
#include<iostream>
#include<string>
usingnamespace std;
class Node
{
public:
int value;
Node * next;
Node();
Node(int);
};
Node::Node():value(0),next(NULL){}
Node::Node(int v):value(v),next(NULL){}
void Print(Node* h)
{
while(h)
{
cout<<" -> "<<h -> value;
h = h -> next;
}
cout<<endl;
}
void Create(Node *& head)
{
head = new Node(1);
Node * tmp = head;
string s; char c;
cin>>s;
s="";
for(int i =0; i < s.length(); i++)
c = s.at(i);
char v = c = '0';
}
void DeleteAll(Node*& head)
{
Node* tmp;
while(head)
{
tmp = head;
head = head->next;
delete tmp;
}
}
int main()
{
char operation;
int result;
Node * h1 = NULL;
Node * h2 = NULL;
cout<<"Enter first number:";
Create(h1);
cin.ignore();
cout<<endl;
cout<<"Enter second number";
Create(h2);
cin.ignore();
cout<<endl;
cout<<"What operation you want, + or -";
cin>>operation;
if( operation == '+' )
{
result = h1 ->value + h2 ->value;
cout<<"Result="<<result<<endl;
}
elseif( operation == '-' )
{
result = h1 ->value - h2 ->value;
cout<<"Result="<<result<<endl;
}
cin.ignore();
cin.ignore();
}
Okay, fixed up your program so it compiles. Then I ran it, it took in values but the result was either 2 or 0. So, first problems I spotted:
1. In function Create(Node &* head), line 31-32: You take in string s, but then you throw away its value by adding the s="";. What are you trying to do there?
2. In the program, all lines: You aren't using the function Print(node* h); anywhere in your program, so make use of it or throw it out. You also aren't using the function DeleteAll(Node*& head); so use it or delete it.
That's all I got for now, maybe someone with a bit more expertise can help you.
#include<iostream>
#include<string>
usingnamespace std;
class Node
{
public:
int value;
Node * next;
Node();
Node(int);
};
Node::Node():value(0),next(NULL){}
Node::Node(int v):value(v),next(NULL){}
void Create(Node *& head)
{
head = new Node(1);
Node * tmp = head;
//what i'm trying to do here is to convert the string int inger
//and put it in a linked list so the user can add or subtract
//very large numbers.
string s; char c;
cin>>s;
for(int i =0; i < s.length(); i++)
c = s.at(i);
char v = c = '0';
}
int main()
{
char operation;
int result;
Node * h1 = NULL;
Node * h2 = NULL;
cout<<"Enter first number:";
Create(h1);
cin.ignore();
cout<<endl;
cout<<"Enter second number";
Create(h2);
cin.ignore();
cout<<endl;
cout<<"What operation you want, + or -";
cin>>operation;
if( operation == '+' )
{
result = h1 ->value + h2 ->value;
cout<<"Result="<<result<<endl;
}
elseif( operation == '-' )
{
result = h1 ->value - h2 ->value;
cout<<"Result="<<result<<endl;
}
cin.ignore();
cin.ignore();
}