PDA

View Full Version : مبتدی: خطا گرفتن کامپایلر از case



raminlich
یک شنبه 15 تیر 1393, 18:23 عصر
سلام نیمدونم چرا کامپایلر نمیزاره دیگه case به این اضافه کنم:ناراحت:
#include <iostream>
#include <fstream>
#include <string>
#include <conio.h>
using namespace std;
void output(float[],int);
int main()
{
int farvardin[31],ordibehesht[31],khordad[31],tir[31],mordad[31],shahrivar[31],
mehr[30],aban[30],azar[30],dey[30],bahman[30],esfand[29];

float far[16],ord[16],khor[16],ti[16],mor[16],shahr[16],
meh[15],aba[15],aza[15],de[15],ba[15],esf[14],dar,s,z;

ofstream list("list.txt",ios::app);
ofstream sal("sal.txt",ios::app);
ofstream farv("far.txt",ios::app);

string name;
int tedad,gheymatye,newadd,i=0,gheymateto,co=0;
cout<<"Enter '1' For Adding:"<<endl;
cout<<"Enter '2' For Accounting:"<<endl;
cin>>newadd;
switch(newadd){
case 1:
//New Adding---------------------------------------------------------------------------//
cout<<"Enter your Stock Name:"<<endl;
cin>>name;
cout<<"Enter your Amount of stock:"<<endl;
cin>>tedad;
list<<name<<' '<<tedad<<" ";
cout<<endl;
break;
//end of Adding------------------------------------------------------------------------//
case 2:
//being of process--------------------------------------------------------------------//
string na; int ted;
cout<<"Enter your Stock Name For Accounting:";
cin>>na;
ifstream list;
list.open("list.txt");
bool found = false;
while (list>>name>>tedad)
{
if(na==name)
{
cout<<"Enter Your Yesterday Price:"<<endl;
cin>>gheymatye;
s=gheymatye*tedad;
cout<<"Enter Your Today Price:"<<endl;
cin>>gheymateto;
z=gheymateto*tedad;
found = true;
}
}
if (!found)
{
cout<<"Error Stock Name was not found!";
break;
}
farvardin[i]=s;
i++;
farvardin[i]=z;
for(int k=0;k<=i;k++){
sal<<farvardin[k]<<endl;
}
s*=100;
dar=(s/z);
dar-=100;
cout<<"%"<<dar;
far[co]=dar;
for(int j=0;j<=i;j++)
farv<<far[j]<<endl;
break;
case 3:
}
}
این case 3 که بنویسم چند تا خطا میگیره:عصبانی++:

hadi0x7c7
یک شنبه 15 تیر 1393, 19:14 عصر
خب باید یه چیزی داخل این بنویسید، حداقلش یه ; هست

emadrezvani
یک شنبه 15 تیر 1393, 19:50 عصر
شما case 2 رو نوشتید و بعد break گذاشتید. تا اینجا درست. اما باید برای case 3 هم همین کار رو انجام بدید.

مسعود اقدسی فام
یک شنبه 15 تیر 1393, 21:18 عصر
زمانی که داخل case‌ متغیر جدیدی تعریف می‌کنید. (مثل na و ted در case 2) کل case‌ رو با {} بلاک بندی کنید تا به مشکل نخورید. یعنی:



case 1:
// your code
break;
case 2:
{
string na; int ted;
// your code;
}
case 3:
// your code
break;