#include<iostream>
#include<string>
struct student {
std::string name;
int age;
float marks;
};
student initiateStudent(std::string name, int age, float marks)
{
student s;
s.age = age;
s.marks = marks;
s.name = name;
return s;
}
student* highestScore(student** stud, int total)
{
float temp = (*stud)->marks;
student **counter= new (student*);
*counter = *stud;
for (int i = 0; i < total; i++)
{
// std::cout<<(*stud)->marks;
if (temp < (*stud)->marks)
{
*counter = *stud;
temp = (*stud)->marks;
}
(*stud)++;
}
*stud = *counter;
delete counter;
return *stud;
}
int main()
{
int totalStudents = 1;
std::string name;
int age;
float marks;
std::cin >> totalStudents;
student *stud = new student[totalStudents];
for (int i = 0; i < totalStudents; i++) {
std::cout << "\nEnter Name: ";
std::cin >> name;
std::cout << "\nEnter age: ";
std::cin >> age;
std::cout << "\nEnter Marks: ";
std::cin >> marks;
stud[i] = initiateStudent(name, age, marks);
//std::cout << "\n Name: " << stud[i].name << "\n" << stud[i].marks;
}
student *topper = highestScore(&stud, totalStudents);
//std::cout << "\nPrinting in Main : " << topper->name;
std::cout<<std::endl << topper->name << " is the topper with " << topper->marks << " marks" << std::endl;
delete[] stud;
std::cin.get();
return 0;
}
вот ошибка, которая появляется, когда я заканчиваю ввод значений для всех студентов: Визуальная ошибка студии
, но когда я запускаю тот же код в коде:блоки, он работает гладко и отображает вывод:
тот же код на кодовых блоках
, но даже в окне кодового блока отображается ошибка, в чем проблема, любая помощь поможетбудь великим.