Hỏi bài tập C++ bị lỗi strcmp

mình đang sài Dev C++, có mấy cái hàm mình rất bị rối nhất là hàm struct và các hàm cắt chuỗi
nếu ai đã hiểu hết về Dev thì cho mình hỏi mấy cái vấn đề đi ạ
 

VSupport

Ngây thơ trong tối
Reply: Tư vấn dùm mình đi ạ

Bạn cứ đặt câu hỏi cụ thể đi :D
 
Reply: Tư vấn dùm mình đi ạ

à bạn mình không biết đưa code lên bạn có thể chỉ dùm mình được không sau đó mình đưa bài mình lên
 
Reply: Tư vấn dùm mình đi ạ

Mã:
#include <iostream>#include <stdio.h>
#include <string>
struct diemthi
{
 float toan;
 float ly;
 float hoa;
};
struct sinhvien
{
 char masv[10];
 char hoten[50];
 char ngaysinh[20];
 char sbd[20];
 diemthi diem;
};


void nhap1sv(sinhvien &sv);
void xuat(sinhvien sv);
void nhapmangsv(sinhvien sv[],int n);
void xuatmang(sinhvien sv[],int n);
int timsv(sinhvien a[],int n);
int timvitrisv(sinhvien a[],int n);
void timlietketen(sinhvien a[],int n);


int main()
{
  sinhvien sv[10]; int n; int z; int vt;
  cout<<"Nhap n"; cin>>n;
   nhapmangsv(sv,n);
 	xuatmang(sv,n);
  
  cout<<"vi tri can tim la:"<<timvitrisv(sv,n);
 }


void nhap1sv(sinhvien &sv)
{ cout<<"masv:";gets(sv.masv);
  cout<<"hoten:";gets(sv.hoten);
  cout<<"ngay sinh:"; gets(sv.ngaysinh);
  cout<<"so bao danh:"; gets(sv.sbd);
  cout<<"diem toan:"; cin>>sv.diem.toan;
  cout<<"diem ly:"; cin>>sv.diem.ly;
  cout<<"diem hoa:"; cin>>sv.diem.hoa;
}
void xuat(sinhvien sv)
{
 cout<<"\n"<<"masv:"<<sv.masv<<"\n";
 cout<<"\n"<<"hoten:"<<sv.hoten<<"\n";
 cout<<"ngaysinh:"<<sv.ngaysinh<<"\n";
 cout<<"sbd:"<<sv.sbd<<"\n";
 cout<<"diem toan:"<<sv.diem.toan<<"\n";
 cout<<"diem ly:"<<sv.diem.ly<<"\n";
 cout<<"diem hoa:"<<sv.diem.hoa<<"\n";
}
void nhapmangsv(sinhvien sv[],int n)
 {
  for(int i=0;i<n;i++)
  {
  cout<<"-------------Nhap sv thu["<<i<<"]------------"<<"\n";
  nhap1sv(sv[i]);
  }
 }


void xuatmang(sinhvien sv[],int n)
{
for(int i=0;i<n;i++)
  {
  cout<<"-------------Xuat sv thu["<<i<<"]------------"<<"\n";
  xuat(sv[i]);
  }
}




int timsv(sinhvien a[],int n)
{  char x[100];
  int i=0;
  cout<<"nhap masv"; gets(x);
 while(strcmp(a[i].masv,x)!=0 &&i<n) i++;
  if(i==n) return 0;
 else return 1;
}


int timvitrisv(sinhvien a[],int n)
{
	char f[100];
  int i=0;
  cout<<"nhap masv"; gets(f);
 while(stricmp(a[i].masv,f)!=0 &&i<n) i++;
  if(i==n) return -1;
 else return i;
}


void timlietketen(sinhvien a[],int n)
{
	char f[100];
  int i=0;
  cout<<"nhap hoten:"; gets(f);
	while(i<n&& stricmp(a[i].hoten,f)==0)
	{
	 xuat(a[i]);
	 i++;
	}
}
chưa gì nó bị lỗi ở cout<<"nhap n ";cin>>n;
 

Ngọc Huyền1

Công Chúa Nhỏ
Reply: Tư vấn dùm mình đi ạ

Mã:
#include <iostream>#include <stdio.h>
#include <string>
struct diemthi
{
 float toan;
 float ly;
 float hoa;
};
struct sinhvien
{
 char masv[10];
 char hoten[50];
 char ngaysinh[20];
 char sbd[20];
 diemthi diem;
};


void nhap1sv(sinhvien &sv);
void xuat(sinhvien sv);
void nhapmangsv(sinhvien sv[],int n);
void xuatmang(sinhvien sv[],int n);
int timsv(sinhvien a[],int n);
int timvitrisv(sinhvien a[],int n);
void timlietketen(sinhvien a[],int n);


int main()
{
  sinhvien sv[10]; int n; int z; int vt;
  cout<<"Nhap n"; cin>>n;
   nhapmangsv(sv,n);
     xuatmang(sv,n);
  
  cout<<"vi tri can tim la:"<<timvitrisv(sv,n);
 }


void nhap1sv(sinhvien &sv)
{ cout<<"masv:";gets(sv.masv);
  cout<<"hoten:";gets(sv.hoten);
  cout<<"ngay sinh:"; gets(sv.ngaysinh);
  cout<<"so bao danh:"; gets(sv.sbd);
  cout<<"diem toan:"; cin>>sv.diem.toan;
  cout<<"diem ly:"; cin>>sv.diem.ly;
  cout<<"diem hoa:"; cin>>sv.diem.hoa;
}
void xuat(sinhvien sv)
{
 cout<<"\n"<<"masv:"<<sv.masv<<"\n";
 cout<<"\n"<<"hoten:"<<sv.hoten<<"\n";
 cout<<"ngaysinh:"<<sv.ngaysinh<<"\n";
 cout<<"sbd:"<<sv.sbd<<"\n";
 cout<<"diem toan:"<<sv.diem.toan<<"\n";
 cout<<"diem ly:"<<sv.diem.ly<<"\n";
 cout<<"diem hoa:"<<sv.diem.hoa<<"\n";
}
void nhapmangsv(sinhvien sv[],int n)
 {
  for(int i=0;i<n;i++)
  {
  cout<<"-------------Nhap sv thu["<<i<<"]------------"<<"\n";
  nhap1sv(sv[i]);
  }
 }


void xuatmang(sinhvien sv[],int n)
{
for(int i=0;i<n;i++)
  {
  cout<<"-------------Xuat sv thu["<<i<<"]------------"<<"\n";
  xuat(sv[i]);
  }
}




int timsv(sinhvien a[],int n)
{  char x[100];
  int i=0;
  cout<<"nhap masv"; gets(x);
 while(strcmp(a[i].masv,x)!=0 &&i<n) i++;
  if(i==n) return 0;
 else return 1;
}


int timvitrisv(sinhvien a[],int n)
{
    char f[100];
  int i=0;
  cout<<"nhap masv"; gets(f);
 while(stricmp(a[i].masv,f)!=0 &&i<n) i++;
  if(i==n) return -1;
 else return i;
}


void timlietketen(sinhvien a[],int n)
{
    char f[100];
  int i=0;
  cout<<"nhap hoten:"; gets(f);
    while(i<n&& stricmp(a[i].hoten,f)==0)
    {
     xuat(a[i]);
     i++;
    }
}
chưa gì nó bị lỗi ở cout<<"nhap n ";cin>>n;
thêm using namespace std vào #include<iostream>
 

VSupport

Ngây thơ trong tối
Reply: Tư vấn dùm mình đi ạ

Thêm cái này: using namespace std ;

Thì bạn so sánh trực tiếp nhé, đừng dùng strcmp nữa :gach:

Tức là đổi thành: while(a.masv==x&&i<n) i++;
 

Thống kê

Chủ đề
100,772
Bài viết
467,615
Thành viên
339,861
Thành viên mới nhất
Trái cây sấy Việt Nam
Top