0x80000003 运行带有函数的程序时出错
0x80000003 Error when running program with functions
float average1;
cout << "Welcome to the weighted average calulator.nPlease enter your first grade:";
cin >> average1;
float weight1;
cout << "Enter the weight (not the weight acheived):";
cin >> weight1;
float grade2;
cout << "Enter the second grade:";
cin >> grade2;
float weight2;
cout << "Enter the weight of the second grade:";
cin >> weight2;
float grade3;
cout << "Enter your third grade:";
cin >> grade3;
float weight3;
cout << "The weight of it?:";
cin >> weight3;
float grade4;
cout << "You know what to do...:";
cin >> grade4;
float weight4;
cout << "Bet you're getting tired of this:";
cin >> weight4;
float grade5;
cout << "Enter the grade...:";
cin >> grade5;
float weight5;
cout << "If you don't know what to do now, you're stupid:";
cin >> weight5;
float grade6;
cout << "Grade please...:";
cin >> grade6;
float weight6;
cout << "Being a teacher can be annoying right, all these weights and grades. (Enter the weight):";
cin >> weight6;
float grade7;
cout << "Unless you're a student who's trying to figure out his grades. Trust me it can'be that bad. (Grade please, the 7th one):";
cin >> grade7;
float weight7;
cout << "Just keep working hard... Weight please:";
cin >> weight7;
float grade8;
cout << "Enter the 8th grade:";
cin >> grade8;
float weight8;
cout << "The weight of said grade?:";
cin >> weight8;
float grade9;
cout << "What's the 9th grade:";
cin >> grade9;
float weight9;
cout << "The weight of the 9th grade?:";
cin >> weight9;
float grade10;
cout << "The tenth grade? Enter it now:";
cin >> grade10;
float weight10;
cout << "Enter the weight of the tenth grade:";
cin >> weight10;
float grade11;
cout << "The 11th grade:";
cin >> grade11;
float weight11;
cout << "The weight of the 11th grade:";
cin >> weight11;
float grade12;
cout << "The 12th grade:";
cin >> grade12;
float weight12;
cout << "The weight of that grade:";
cin >> weight12;
float grade13;
cout << "This is getting boring isn't it? The 13th grade please:";
cin >> grade13;
float weight13;
cout << "Just keep going I guess, The weight of the 13th grade please?";
cin >> weight13;
float grade14;
cout << "The 14th grade is?:";
cin >> grade14;
float weight14;
cout << "The weight of the 14th grade?:";
cin >> weight14;
float check;
check = weight1 + weight2 + weight3 + weight4 + weight5 + weight6 + weight7 +
weight8 + weight9 + weight10 + weight11 + weight12 + weight13 + weight14;
float under;
under = check;
float increase;
increase = 100 / under;
float averagedecimal1;
averagedecimal1 = average1 / 100;
float averagedecimal2;
averagedecimal2 = grade2 / 100;
float weightdecimal1;
weightdecimal1 = weight1 / 100;
float weightdecimal2;
weightdecimal2 = weight2 / 100;
float weighted1;
weighted1 = averagedecimal1 * weightdecimal1;
float weighted2;
weighted2 = averagedecimal2 * weightdecimal2;
float gradedecimal3;
gradedecimal3 = grade3 / 100;
float weightdecimal3;
weightdecimal3 = weight3 / 100;
float weighted3;
weighted3 = gradedecimal3 * weightdecimal3;
float gradedecimal4;
gradedecimal4 = grade4 / 100;
float weightdecimal4;
weightdecimal4 = weight4 / 100;
float weighted4;
weighted4 = gradedecimal4 * weightdecimal4;
float gradedecimal5;
gradedecimal5 = grade5 / 100;
float weightdecimal5;
weightdecimal5 = weight5 / 100;
float weighted5;
weighted5 = gradedecimal5 * weightdecimal5;
float gradedecimal6;
gradedecimal6 = grade6 / 100;
float weightdecimal6;
weightdecimal6 = weight6 / 100;
float weighted6;
weighted6 = gradedecimal6 * weightdecimal6;
float gradedecimal7;
gradedecimal7 = grade7 / 100;
float weightdecimal7;
weightdecimal7 = weight7 / 100;
float weighted7;
weighted7 = gradedecimal7 * weightdecimal7;
float gradedecimal8;
gradedecimal8 = grade8 / 100;
float weightdecimal8;
weightdecimal8 = weight8 / 100;
float weighted8;
weighted8 = gradedecimal8 * weightdecimal8;
float gradedecimal9;
gradedecimal9 = grade9 / 100;
float weightdecimal9;
weightdecimal9 = weight9 / 100;
float weighted9;
weighted9 = gradedecimal9 * weightdecimal9;
float gradedecimal10;
gradedecimal10 = grade10 / 100;
float weightdecimal10;
weightdecimal10 = weight10 / 100;
float weighted10;
weighted10 = gradedecimal10 * weightdecimal10;
float gradedecimal11;
gradedecimal11 = grade11 / 100;
float weightdecimal11;
weightdecimal11 = weight11 / 100;
float weighted11;
weighted11 = gradedecimal11 * weightdecimal11;
float gradedecimal12;
gradedecimal12 = grade12 /100;
float weightdecimal12;
weightdecimal12 = weight12 / 100;
float weighted12;
weighted12 = gradedecimal12 * weightdecimal12;
float gradedecimal13;
gradedecimal13 = grade13 / 100;
float weightdecimal13;
weightdecimal13 = weight13 / 100;
float weighted13;
weighted13 = gradedecimal13 * weightdecimal13;
float gradedecimal14;
gradedecimal14 = grade14 / 100;
float weightdecimal14;
weightdecimal14 = weight14 / 100;
float weighted14;
weighted14 = gradedecimal14 * weightdecimal14;
float weightedscore13;
weightedscore13 = weighted1 + weighted2 + weighted3 + weighted4 + weighted5 +
weighted6 + weighted7 + weighted8 + weighted9 + weighted10 +
weighted11 + weighted12 + weighted13 + weighted14;
float last13;
last13 = weightedscore13 * 100;
float corrected;
corrected = last13 * increase;
cout << "Your weighted average is:";
cout << corrected;
cout << "%" <<endl;
cin.ignore();
cin.get();
return 0;
每次我运行这个程序时,在进入 1 年级、2 年级和有时是 3 年级时,程序都会崩溃,并显示错误0x80000003指示内存损坏。我还没有找到解决方案。感谢所有帮助。
好的,您已经做了大量工作来输入所有这些信息。 下面,我有你相同的代码,清理了一点,也许,让它更好地处理加权平均。 此外,我还添加了循环并将所有字符串放在一个位置,以便在以后添加更多"等级"和"加权平均值"时变得更加容易。
请注意 for 循环如何删除您被迫输入的几乎所有冗余代码。 没有更多的一页又一页的cin/cout。 还要注意局部变量的数组,使按顺序处理条目变得更加容易。 还要注意他们是如何使实际的数学非常干净易读的。 最后,请注意kNumGrades
常量。 这个变量现在控制代码所需的条目数。
static const kNumGrades = 14;
int main(void)
{
const char *userString[kNumGrades][2] =
{
{
"Welcome to the weighted average calulator.nPlease enter your first grade:",
"Enter the weight (not the weight acheived):",
},
{
"Enter the second grade:",
"Enter the weight of the second grade:"
},
{
"Enter your third grade:",
"The weight of it?:",
},
{
"You know what to do...:",
"Bet you're getting tired of this:",
},
{
"Enter the grade...:",
"If you don't know what to do now, you're stupid:",
},
{
"Grade please...:",
"Being a teacher can be annoying right, all these weights and grades. (Enter the weight):",
},
{
"Unless you're a student who's trying to figure out his grades. Trust me it can'be that bad. (Grade please, the 7th one):",
"Just keep working hard... Weight please:",
},
{
"Enter the 8th grade:",
"The weight of said grade?:",
},
{
"What's the 9th grade:",
"The weight of the 9th grade?:",
},
{
"The tenth grade? Enter it now:",
"Enter the weight of the tenth grade:",
},
{
"The 11th grade:",
"The weight of the 11th grade:",
},
{
"The 12th grade:",
"The weight of that grade:",
},
{
"This is getting boring isn't it? The 13th grade please:",
"Just keep going I guess, The weight of the 13th grade please?",
},
{
"The 14th grade is?:",
"The weight of the 14th grade?:",
},
};
float grade[kNumGrades];
float weight[kNumGrades];
float weigthSum = 0;
for(int i=0; i<kNumGrades; i++)
{
cout << userString[0][i];
cin >> grade[i];
cout << userString[1][i];
cin >> weight[i];
weigthSum += weight[i];
}
float weightedScore = 0;
for(int i=0; i<kNumGrades; i++)
{
weightedScore += grade[i] * weight[i] / weigthSum;
}
cout << "Your weighted average is:";
cout << weightedScore;
cout << "%" << endl;
cin.ignore();
cin.get();
return 0;
}
相关文章:
- 重载操作程序时出错>>用于类中的字符串 memebr
- 分段错误当我试图运行程序时出错
- 使用 Visual Studio 2019 构建 Hello World wxwidgets 应用程序时出错
- 在另一台 PC 上执行程序时加载 SDL2 共享库时出错
- 修改气泡排序的程序出错
- 包含多维数组的程序出错
- 程序出错C++
- 检查完美的程序出错了
- 带有私有构造函数的程序出错
- LunarLander程序出错:符号未解析
- C++程序出错
- 结构:初始化程序出错
- 编译简单的应用程序出错
- 在树莓派上编译c++ opencv应用程序出错
- 链接基于Qt的应用程序出错
- 简单数学程序出错
- 具有未定义行为但从未实际执行的表达式是否会使程序出错
- 目录列表程序出错,c++
- Qt LNK2019 基本 Qt5 应用程序出错
- 我的简单阶乘计算器c++程序出错了吗?