-2
#include <conio.h>
#include <iostream>
#include <stdlib.h>
#include <math.h>
#include <string.h>
using namespace std;

struct data{
char tanggal[20],kode[20],nama[20];
int jumlah[20],harga[20];
int modal[20]={jumlah[20]*harga[20]};
};
data batas[100];
int a,b,c,d;

void inputdata(){
   cout<<"\nJumlah Data Yang Akan diinput (max 10) : ";
   cin>>b;
   d=0;
   for(c=0;c<b;c++){
   d=d+1;
   cout<<"\nData ke-"<<d<<endl;
   cout<<"Tanggal Produksi\t: ";
   cin>>batas[a].tanggal;
   cout<<"Kode Produk\t: ";
   cin>>batas[a].kode;
   cout<<"Nama Produk\t: ";
   cin>>batas[a].nama;
   cout<<"Jumlah Produksi\t: ";
   cin>>batas[a].jumlah;
   cout<<"Harga Pokok Penjualan (HPP)\t: ";
   cin>>batas[a].harga;
   cout<<"Modal\t: ";
   cout<<batas[a].modal;
   cout<<endl;
   a++;
   }
   getch();
   system("cls");
   }

That is my code, and this is error that I got

[Error] no match for 'operator>>' (operand types are 'std::istream {aka std::basic_istream<char>}' and 'int [20]')

How to fix it ?

cigien
  • 57,834
  • 11
  • 73
  • 112
  • 3
    You must include the full error, including the line it appeared on. Also, is `a` initialized anywhere? – Random Davis Nov 09 '20 at 18:39
  • 3
    `batas[a].jumlah;`(and anothers) is `int` array. `cin` does not know what it is. Use loops. –  Nov 09 '20 at 18:41
  • Unrelated: [`using namespace std;` is bad.](https://stackoverflow.com/questions/1452721/why-is-using-namespace-std-considered-bad-practice) Here is a small piece of your program compiled with an up-to-date C++ compiler: https://godbolt.org/z/EWW1EG Good luck figuring that mess out if you don't already know what the problem is.. – user4581301 Nov 09 '20 at 18:45
  • 1
    About `int modal[20]={jumlah[20]*harga[20]};`. What is that? –  Nov 09 '20 at 18:45
  • You can simplify your program by using `std::string` for text instead of character arrays. Character arrays can overflow. Beware if the character array is not terminated by nul character. – Thomas Matthews Nov 09 '20 at 20:18
  • Debugging questions should have a [mre]. Thinking about "minimal": do you get the same error if you trim your structure down to `struct data{ int jumlah[20]; };` and similarly trim your `inputdata()` function? You might also want to try trimming off your global variables other than `batas`, but be warned: the fact that you do not make real use `c` or `d` inside your loop might lead you to discover the error on your own. – JaMiT Nov 09 '20 at 22:16
  • Debugging questions often should also have an explanation of what the code is supposed to do, rather than allowing us to decide what we want your code to do. In this case, you should point out which line triggers the error message and tell us what you believe that line accomplishes. Beware a common pitfall -- do not sacrifice clarity for brevity in your explanation. – JaMiT Nov 09 '20 at 22:23

1 Answers1

1

you cannot std::cout << int array you have to use a for loop for every element in the array I know I should not judge your code but please try to use whitespace when using {}

just a guy
  • 137
  • 7