Problem in this exercise

I want to wrote code for this exercise
Possible help me to write a code
look at image
http://www.maxforums.net/uploaded/89495/1269905022.png
what are you trying to do with these matricies?
OP, I'd strongly advise you to read this: http://www.cplusplus.com/forum/articles/1295/
i want some help :)
whats problem in this code


#include<iostream>
#include <string>
using namespace std;

int main()
{

string Item="";

char name[50] ;
cout<< "enter ur name";
cin.getline ( name, 50 );


char prodcut[50];
cout<< "enter ur name";
cin.getline ( prodcut, 50 );



string sale [name][prodcut];

int n,m;
for (n=0;n<name[n];n++)
for (m=0;m<prodcut[m];m++)
{
cout<<"\nplease enter the name of index ["<<n<<" ] and [ "<<m<<" ] \n";
cin>>Item;

sale[n][m]=Item;
cout<< sale[n][m];
}
cin.getline ( );
}
Last edited on
Use [c0de][/c0de] tags next time please.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include<iostream>
#include <string>
using namespace std;

int main()
{

string Item="";

char name[50] ;
cout<< "enter ur name";
cin.getline ( name, 50 );


char prodcut[50];
cout<< "enter ur name";
cin.getline ( prodcut, 50 );



string sale [name][prodcut];

int n,m;
for (n=0;n<name[n];n++)
for (m=0;m<prodcut[m];m++)
{
cout<<"\nplease enter the name of index ["<<n<<" ] and [ "<<m<<" ] \n";
cin>>Item;

sale[n][m]=Item;
cout<< sale[n][m];
}
cin.getline ( );
}


For one, your for loop isn't nested as you want it to be. Your first for loop doesn't have brackets around its inner for loop.
1
2
for(n=0;n<name[n];n++) //missing brackets after this
for(m=0;m<prodcut[m];m++)


I don't understand the use of prodcut and name, when you ask the name twice and use name and prodcut (char arrays) as dimensions for an array.
1
2
3
char name[50];
char prodcut[50];
string sale[name][prodcut]; //char array dimensions? 
Last edited on
Topic archived. No new replies allowed.