Chào mọi người, mình có một chương trình bị lỗi, mọi người có thể xem qua chương trình bị lỗi đoạn nào ko ạ
(Mình nghĩ nó bị lỗi ở phần loop đoạn Nhập dữ liệu vào mảng )
#include <iostream>
#include <string>
#include <malloc.h>
using namespace std;
// Struct of Consumer:
struct consumer_list {
int Bill_month;
int Electric_consumption;
string Address;
string Name;
string Code;
};
void consumer_Input(consumer_list list, bool cond);
void consumer_Outut(consumer_list list);
int main()
{
bool stop;
int count = 0;
int n = 1;
consumer_list *p = NULL;
for (int i = 0;; i++)
{
n++;
p = (consumer_list*)malloc(n * sizeof(int));
consumer_Input(*(p + i), stop);
count++;
if (stop == true)
{
break;
}
}
if (count == 0)
{
cout << "Khong co khach hang thu !";
return 0;
}
fflush(stdin);
char cond;
cout << "Ban co muon Trinh du lieu ban vua nhap? (y/n)"; cin >> cond;
if (cond == 'y')
{
system("cls");
for (int i = 0; i < count - 1; i++)
{
consumer_Outut(*(p + i)); // problem has'nt been solve!
}
}
else if (cond == 'n')
return 0;
return 0;
}
void consumer_Input(consumer_list list, bool cond)
{
cout << "Thang Thu: "; cin >> list.Bill_month;
if (list.Bill_month == 0)
{
cond = true;
}
fflush(stdin);
cout << "Ten khach hang: "; getline(cin, list.Name);
cout << "Ma khach hang: "; getline(cin, list.Code);
fflush(stdin);
cout << "Dia chi : "; getline(cin, list.Address);
fflush(stdin);
cout << "Dien nang tieu thu: "; cin >> list.Electric_consumption;
cout << endl;
cout << "--------------------------------------------------------------------";
cout << endl;
return;
}
void consumer_Outut(consumer_list list)
{
cout << "\nTen khach hang: " << list.Name;
cout << "\n\tMa khach hang: " << list.Code;
cout << "\n\tDia chi khach hang: " << list.Address;
cout << "\n\tThang thu cua khach hang: " << list.Bill_month;
cout << "\n\tDien nang tieu thu: " << list.Electric_consumption;
cout << endl;
cout << "----------------------------------------------------";
cout << endl;
}

83% thành viên diễn đàn không hỏi bài tập, còn bạn thì sao?