problem in pass by reference in array

Hi, i need someone to check for me what wrong with my coding!!!
If anyone know what is my mistake pls teach me the proper one
Thk here first for people that helping me here.

#include <iostream>
using namespace std;
struct totalSales
{
char name[50];
float price;
int copy_a;
int copy_s;
float sales;

};
void change (totalSales &);
int main ()
{
totalSales t1[2];
int a,b,s;
float total=0;
char ch;


for (a=0;a<2;a++)
{
cout<<"Enter the book title:"<<endl;
cin.getline (t1[a].name,50,'\n');
cout<<"Price for the book:"<<endl;
cin>>t1[a].price;
cout<<"The copy available:"<<endl;
cin>>t1[a].copy_a;
cout<<"The copy that sale:"<<endl;
cin>>t1[a].copy_s;
t1[a].sales=t1[a].price*t1[a].copy_s;
total=total+t1[a].sales;
cin.ignore ();
cout<<endl;
}
cout<<"Do you need any changing?(y/n)"<<endl;
cin>>ch;
while (ch == 'y' || ch == 'Y')
{
for (a=0;a<2;a++)
{
s=change (t1);// i wan change information for whole statement
}
}

cout<<endl<<endl<<"The information for the books are as follow:"<<endl<<endl;
for (b=0;b<2;b++)
{
cout<<"Title:"<<t1[b].name<<endl;
cout<<"The price of the book:"<<t1[b].price<<endl;
cout<<"Copy available:"<<t1[b].copy_a<<endl;
cout<<"Copy already sold:"<<t1[b].copy_s<<endl;
cout<<"Total sales for the book is:"<<t1[b].sales<<endl<<endl<<endl;
}
cout<<"The total daily sales is :"<<total<<endl;
return 0;
}
void change ( totalSales &m) //my function defination
{
int a;
float price;
char text[50];
int copy_a,copy_s;

for (a=0;a<2;a++)
{
cout<<"New title:"<<endl;
cin.getline (text,50);
cout<<"New Price:"<<endl;
cin>>price;
cout<<"Copy sales:"<<endl;
cin>>copy_s;
cout<<"Copy available:"<<endl;
cin>>copy_a;
m.name=text;
m.price=price;
m.copy_a=copy_a;
m.copy_s=copy_s;
}
}

Thk again for helping me....
Last edited on
Don't forget to use code tags. code is totally unreadable without them.

Is this what you want?
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include <iostream>

using namespace std;

struct totalSales{
	char name[50];
	float price;
	int copy_a;
	int copy_s;
	float sales;
};

void change ( totalSales m[2] ){
	int a;
	float price;
	char text[50];
	int copy_a,copy_s;
	for(int a =0; a < 2; a++){
		cout<<"New title:"<<endl;
		cin.getline (text,50);
		cout<<"New Price:"<<endl;
		cin>>price;
		cout<<"Copy sales:"<<endl;
		cin>>copy_s;
		cout<<"Copy available:"<<endl;
		cin>>copy_a;
		//m[a].name=text;
		m[a].price=price;
		m[a].copy_a=copy_a;
		m[a].copy_s=copy_s;
	}
}

int main(){
	totalSales t1[2];
	int a,b;
	float total=0;
	char ch;
	for (a=0;a<2;a++){
		cout<<"Enter the book title:"<<endl;
		cin.getline (t1[a].name,50,'\n');
		cout<<"Price for the book:"<<endl;
		cin>>t1[a].price;
		cout<<"The copy available:"<<endl;
		cin>>t1[a].copy_a;
		cout<<"The copy that sale:"<<endl;
		cin>>t1[a].copy_s;
		t1[a].sales=t1[a].price*t1[a].copy_s;
		total=total+t1[a].sales;
		cin.ignore ();
		cout<<endl;
	}
	cout<<"Do you need any changing?(y/n)"<<endl;
	cin>>ch;
	while (ch == 'y' || ch == 'Y'){
		change(t1);// I want to change information for whole statement
	}
	cout<<endl<<endl<<"The information for the books are as follow:"<<endl<<endl;
	for (b=0;b<2;b++){
		cout<<"Title:"<<t1[b].name<<endl;
		cout<<"The price of the book:"<<t1[b].price<<endl;
		cout<<"Copy available:"<<t1[b].copy_a<<endl;
		cout<<"Copy already sold:"<<t1[b].copy_s<<endl;
		cout<<"Total sales for the book is:"<<t1[b].sales<<endl<<endl<<endl;
	}
	cout<<"The total daily sales is :"<<total<<endl;
	return 0;
}

Last edited on
How bout mine??
It says "passing float for converting 1 of 'char calc_grade(int)'
I hv displayed part of my codes...
The char calc_grade(int) is shown below...

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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#include<iostream>
#include<stdlib.h>
#include<stdio.h>
#include<conio.h>
#include<fstream>
#include<math.h.>
#include<string>
using namespace std;


void openFile();
void closeFile();
void PressAnyKeyToContinue(void);
void DisplayHeader(void);
int MainMenu (void);
char calc_grade(int mark);
void ViewAllInformation();
void OverallStatistics();

float calc_average(int);
int calc_sum(int);

int choosestatisticssubject();
int displaychooseSubjectmenu();
int SubjectMenu();
int displaystatisticmenu(string x);
int statisticsmenu(string x,int submark);
void average(string x,int mark);
void studentpass(string x,int mark);
void studentfail(string x,int mark);
void Below(string ,int );
void Above(string ,int );
void displaystudent(string ,int );
int averageAll();
int OverallAboveOrBelow(int);
void OverallPassOrFail(int);
void OverallBasedOnGrade();




//-----------------------------------------------------------------------------
//                  View The Contents of A File
//-----------------------------------------------------------------------------
   
void ViewAllInformation()
{ 	
	char grade1,grade2,grade3,avg_grade;
	string name;
	int m1,m2,m3;

	int sumsub1=0,sumsub2=0,sumsub3=0;
	float avgsub1,avgsub2,avgsub3;
	int total=0;

	float avg_mark;
	int count=0;
	


	openFile();
	DisplayHeader();
	cout<<"********************************************************************************\n";
	cout<<" \t  All Information Of Student In My Mark Analyzer\n";
	cout<<"********************************************************************************\n";
	cout<< endl;
	cout << "Name\t\tCP1\tGrade\tMath\tGrade\tEnglish\tGrade\tAverage\tGrade" <<endl; 
	cout << "----------------------------------------------------------------------------" <<endl;
  

	while(!input.eof())
    	{
		input>>name>>m1>>m2>>m3  ;

		grade1=calc_grade(m1);
		grade2=calc_grade(m2);
		grade3=calc_grade(m3);
		avg_grade=calc_grade(avg_mark);

		total=m1+m2+m3;
		avg_mark=(float)total/3;
	
		sumsub1=sumsub1+m1;
		sumsub2=sumsub2+m2;
		sumsub3=sumsub3+m3;
		count++;

		avgsub1=(float)sumsub1/count;
		avgsub2=(float)sumsub2/count;
		avgsub3=(float)sumsub3/count;

		if (!input.fail())    
		{
			cout 

<<name<<"\t\t"<<m1<<"\t"<<grade1<<"\t"<<m2<<"\t"<<grade2<<"\t"<<m3<<"\t"<<grade3<<"\t"<<avg_mark<<"\t"<<

avg_grade<<endl;
		}	
              

	}// end while
		cout <<"********************************************************************************\n";
		cout <<"Average\t\t"<<avgsub1<<"\t\t"<<avgsub2<<"\t\t"<<avgsub3<<endl;
		cout <<"********************************************************************************\n";
		
		input.close();
		closeFile();
}



I hv problem with the grade~~
The grade is in mistake grade...
ex: 89.33 marks shud b grade A but in my program is grade F...

Thanks...
Last edited on
Topic archived. No new replies allowed.