for (int counter = 0; counter > size ; counter ++ )
{
sum = sum + score[counter];
}
average = sum /size;
cout << "The average Score is:" << average << endl;
}
void sortData(string* name, int* score, int size)
{
int index_one, index_two;
char temp;
for ( index_one = 0; index_one < (size - 1); index_one++)
{
for(int index_two = index_one + 1; index_two < size; index_two++)
{
if (name [index_one] > name [ index_two])
{
temp = name [ index_one];
name [index_one] = name [index_two];
name [index_two] = temp;
temp = score [index_one];
score [index_one] = score [index_two];
score [index_two] = temp;
}
}
}
}
void displayData (string *name , int *score, int size)
{
cout << "Name \t\t Score\n";
cout << "---------------------------------";
for (int index = 0; index > size ; index++)
{
cout << name [index] << "\t";
cout << setw(14) << score [index] << endl;
}
}
fsamu2001 0 Newbie Poster
#include<iostream>
#include<string>
#include<iomanip>
using namespace std;
//function prototype
void sortData(string* ,int*);
void calcAverage(int*, int);
void displayData(string* , int*, int);
int main ()
{
// pointer variables
string* name;
int *score;
int size;
int counter;
//dynamic variables
// user enter score
cout<<"How many test scores will you enter?";
cin >> size;
score = new int[size];
name = new string [size];
for(counter = 0; counter< size; counter ++)
{
cout<< "Enter students last name ";
cin >> *(name + counter) ;
cout << " Enter the student's test score: ";
cin >> * (score + counter);
}
}
// function to calculate Average
void calcAverage(int* score, int size)
{
int sum = 0;
float average;
for (int counter = 0; counter > size ; counter ++ )
{
sum = sum + score[counter];
}
average = sum /size;
cout << "The average Score is:" << average << endl;
}
// function to sort student name with the test score respectively.
void sortData(string* name, int* score, int size)
{
int index_one, index_two;
char temp;
for ( index_one = 0; index_one < (size - 1); index_one++)
{
for(int index_two = index_one + 1; index_two < size; index_two++)
{
if (name [index_one] > name [ index_two])
{
temp = name [ index_one];
name [index_one] = name [index_two];
name [index_two] = temp;
temp = score [index_one];
score [index_one] = score [index_two];
score [index_two] = temp;
}
}
}
}
void displayData (string *name , int *score, int size)
{
cout << "Name \t\t Score\n";
cout << "---------------------------------";
for (int index = 0; index > size ; index++)
{
cout << name [index] << "\t";
cout << setw(14) << score [index] << endl;
}
}
Edited by Nick Evan because: Fixed formatting
gerard4143 371 Nearly a Posting Maven
Could you indicate which line is 89.
frogboy77 73 Posting Pro in Training
for (int index = 0; index > size ; index++)
This could be your issue.
Please use code tags, you will get more help.
For this to run size would have to have a negative value and as you increment index it will always be larger, so infinite loop.
Edited by frogboy77 because: n/a
thekashyap 193 Practically a Posting Shark
#include<iostream> #include<string> #include<iomanip> using namespace std; //function prototype void sortData(string* ,int*); void calcAverage(int*, int); void displayData(string* , int*, int); int main () { // pointer variables string* name; int *score; int size; int counter; //dynamic variables // user enter score cout<<"How many test scores will you enter?"; cin >> size; score = new int[size]; name = new string [size]; for(counter = 0; counter< size; counter ++) { cout<< "Enter students last name "; cin >> *(name + counter) ; cout << " Enter the student's test score: "; cin >> * (score + counter); } } // function to calculate Average void calcAverage(int* score, int size) { int sum = 0; float average; for (int counter = 0; counter > size ; counter ++ ) { sum = sum + score[counter]; } average = sum /size; cout << "The average Score is:" << average << endl; } // function to sort student name with the test score respectively. void sortData(string* name, int* score, int size) { int index_one, index_two; char temp; for ( index_one = 0; index_one < (size - 1); index_one++) { for(int index_two = index_one + 1; index_two < size; index_two++) { if (name [index_one] > name [ index_two]) { temp = name [ index_one]; name [index_one] = name [index_two]; name [index_two] = temp; temp = score [index_one]; score [index_one] = score [index_two]; score [index_two] = temp; } } } } void displayData (string *name , int *score, int size) { cout << "Name \t\t Score\n"; cout << "---------------------------------"; for (int index = 0; index > size ; index++) { cout << name [index] << "\t"; cout << setw(14) << score [index] << endl; } }
Line 89 is " temp = name [ index_one];
"
Error is
D:\Workspaces\CodeBlocks\Test\main.cpp|89|error: cannot convert `std::basic_string<char, std::char_traits<char>, std::allocator<char> >' to `char' in assignment|
deref of string* returns string and deref of int* returns int. You're trying to assign a string to a char on line 89. That's the problem.
(PS: Same problem exists 6 lines below where you try to assign int to char. Unfortunately it might work! Fix it.
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.