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

c++ ما هو خطا

مغلق
بدأه alqabtan في 5 نوفمبر 2006 · 3 رد · 568 مشاهدة · في الأسئلة المجابة
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

stack في c++ ما هو خطا

#include <iostream.h>
void main()
{
	int s[5],item,top=-1,c,i;
	do
	{
		cout<<"pash=1,pop=2,exit=3"<<"\n";
		cout<<"choose you option\n";
		cin>>c;
		if(c==1)
			cout<<"enter number to pash/n";
		cin>>item;
		if(item==4)
			cout<<"the Stak is full\n";
			else
			{
			top++;
		s[top]=item;
		cout<<"the stack is ";
		for(i=top;i>=0;i--)
			cout<<s<<"   ";
		cout<<"\n\n\n";
	}
	}
if(c==2)

cout<<"enter number to pop\n";
cin>>item;
if(top==-1)
cout<<"stack is empty\n";
else
{
	item=s[top];
	cout<<"the popped item is"<<item;
	top--;
	cout<<"\n\n stack";
	for(i=top;i>0;i--)
		cout<<s<<"   ";
	cout<<"\n";

}while(c<=2);
}
#2

استاذي حلقة do while لها صيغة معينة

do

}

.

.

.

{

;(.....)while

لماذا if قبل while ؟!

llback.jpg

اشهد ان لا إله إلا الله وان محمدا ً رسول الله

#3

أنصحك أولا باستعمال Switch عوضا عن if..else if..else

if(item==4)

الأصح أن تكتب :

if(top==4)
#4

جرب هذا الكود :

#include <iostream.h>
#include <process.h>
void main()
{
  int s[5],item,top=-1,c,i;
  do
  {
	cout<<"[1] Push\n[2] Pop\n[3] Exit\n\n";
	cout<<"Choose your option : ";  cin>>c;
	switch (c)
	{
	  case 1: if(top==4) cout<<"The stack is full!!\n\n";
		  else {
		cout<<"Enter number to push : ";  cin>>item;
		s[++top]=item;
		cout<<"The stack is : ";
		for(i=top;i>=0;i--)
		  cout<<s<<"   ";
		  cout<<"\n\n";
		   }  break;
	  case 2: if(top==-1)  cout<<"Stack is empty!!\n\n";
		  else {
		 item=s[top--];
		 cout<<"The popped item is : "<<item;
		 cout<<"\n\nThe stack is : ";
		 for(i=top;i>-1;i--)
		   cout<<s<<"   ";
		 cout<<"\n\n";
		  }  break;
	  case 3: exit(0); break;
	}
  }while(1);
}

هذا الموضوع مغلق.

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