الفريق العربي للبرمجةأرشيف المنتديات · 2000 – 2023
نسخة أرشيفية للقراءة فقط — التسجيل والمشاركة مغلقان، والمحتوى محفوظ كما كان.

خطأ في تحويل رقم طويل من string الى int في الـ linked list

بدأه Nouf Bint Turki في 30 ديسمبر 2010 · 2 رد · 485 مشاهدة · في الأسئلة المجابة
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

السلام عليكم ورحمه الله و بركاته

عندي بروجكت مطلوب مني اسوي اله حاسبه باللينكد ليست و اليوزر يقدر يدخل في هاذي الاله ارقام طويله مره

انا توني بالبدايه و طلع لي ايرور وما عرفت ايش هو بالضبط !!!

ياليت احد يساعدني ..

#include<iostream>
#include<string>
using namespace std;


class Calculator
{
public:
	int value;
	Calculator* next;
	Calculator()
	{
		value=0;
		next=NULL;
	}
	Calculator(int v)
	{
		value=v;
		next=NULL;
	}
};


void GetNum(Calculator*& h)
{
	string s=" ";
	cin>>s;
	int n=0;
	int strlen=s.length();
	for (int i=0; i<strlen; i++)
	{
		n= s-'0';
		AddHead(h,n);
	}

}

void Print(Calculator* h)
{
	if(!h) cout<<"List is empty\n";
	while(h)
	{
		cout<<h->value;
		h=h->next;
	}
	cout<<endl;
}
void AddHead(Calculator*& h, int n)
{
	Calculator* tmp= new Calculator(n);
	tmp->next=h;
	h=tmp;
}

int main()
{
	Calculator* num1=NULL;
	Calculator* num2=NULL;
	Calculator* result=NULL;
	char oper;
	while(true)
	{	
		cout<<"Enter the first number:"<<endl;
		GetNum(num1);
		cout<<"Enter the second number:"<<endl;
		GetNum(num2);
	}



	return 0;
}

وشكراً ..

#2

و عليكم السلام ...

فقط قومي بوضع دالة AddHead قبل دالة GetNum ، يجب عليك أن تقومي يتعريف الدالة قبل إستعمالها.

1

Program every day for 20 years and you will become a good programmer. Program every day for 10 years and study algorithms on the side and you will become a great programmer !

على الأقل هذا اللي سمعته ...

#3

ph34r.giflaugh.gif

يعطيك ربي الف عافيه :)

مواضيع مشابهة