#include <iostream>
#include <stack>
#include <string>
using namespace std;
int main()
{
string name;
double gpa;
double high = 0;
stack<string>names;
for (int i=0; i<7; i++)
{
cout << " Enter student's name and gpa " << endl;
cin >> gpa ;
cin >> name ;
}
{
if (gpa > high)
{
high = gpa;
names.push(name);
}
else if (gpa=high)
{
high = gpa;
names.push(name);
}
}
cout << "Highest gpa is"<< high << "Names with highest gpa "<< ??? <<< endl;
system("pause");
return 0;
}
有这些名称和GPA到这些名称的列表,7是确切的。我有算法获得最高的GPA,并且我知道有一些while循环条件用于获取具有最高GPA的人员的姓名。如何显示与某个变量相关联的名称?...请说明此部分
从问题2人有最高的GPA ...我将如何显示这两个这些名称与最高GPA分开?我似乎无法得到那个可以将名称与GPA联系在一起的部分。
帮助将不胜感激。
编辑:有没有更容易的方法在代码中使用while循环内的某个循环?在我使用if (gpa < high)
声明的地方,我是否错过了一些获得GPA最高的名称?
您在'else if'中的条件已损坏。 – 2011-03-11 03:11:55
你的意思是什么意思?这意味着如果gpas等于最高gpa,我想用该gpa显示名称。但是还有其他正确的代码吗? – Surya 2011-03-11 03:15:15
错了。再读一遍。 – 2011-03-11 03:15:55