- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
好的!一切正常。不过现在,我必须添加一个 bool 函数来验证我的用户输入的成绩是否有效……我不知道该怎么做……唉。我什至不知道从哪里开始,但我确实设置了一个原型(prototype)并在底部启动了功能......我必须将它包含在main中吗?如果有,在哪里?
我的教授在春假期间严重地向我们扔了太多东西......无论如何,我必须创建一个 bool 函数来检查而不是检查用户输入的值范围为 0-100,但我完全不知道如何做到这一点,我的程序已经非常复杂了......无论如何,这是代码, bool 函数在底部,我只声明了原型(prototype),因为我不知道我的下一个是什么步骤将是。任何帮助将不胜感激。
int menu();
void DisplayGrades (float, float, float, float, float, float); // In this function, it will display the grades the user enters. Used for choice 2.
float AssignmentGrade(float, float, float, float, float);
float LabTestGrade(float, float, float, float); // Prototypes to help me remember functions.
float LectureTestGrade(float, float, float, float, float);
float PostLabGrade(float, float, float, float, float, float, float, float, float, float);
float QuizGrade (float, float, float, float, float, float, float, float, float, float);
float ClickerGrade (float, float);
bool Gradeisvalid (float);
bool Choiceisvalid (int);
int main()
{
float asgnment = 0, asgnment1 = 0, asgnment2 = 0, asgnment3 = 0,
asgnment4 = 0, labtest = 0, labtest1 = 0, labtest2 = 0,
labtest3 = 0, lecturetest = 0, lecturetest1 = 0, lecturetest2 = 0, // Variables declared
lecturetest3 = 0, lecturetest4 = 0, postlab = 0, p1 = 0, p2 = 0, p3 = 0, p4 = 0,
p5 = 0, p6 = 0, p7 = 0, p8 = 0, p9 = 0, quiz = 0, quiz1 = 0, quiz2 = 0, quiz3 = 0, quiz4 = 0, quiz5 = 0,
quiz6 = 0, quiz7 = 0, quiz8 = 0, quiz9 = 0, clicker = 0, clickergrade = 0, grade = 0;
int choice;
while(1)
{
choice = menu();
if (choice ==4) break;
switch (choice)
{
case 1:
asgnment=AssignmentGrade(asgnment, asgnment1, asgnment2, asgnment3, asgnment4);
labtest = LabTestGrade(labtest, labtest1, labtest2, labtest3);
lecturetest = LectureTestGrade(lecturetest, lecturetest1, lecturetest2, lecturetest3, lecturetest4); // Typed this out to help remind of what I used
postlab = PostLabGrade(postlab, p1, p2, p3, p4, p5, p6, p7, p8, p9);
quiz = QuizGrade(quiz, quiz1, quiz2, quiz3, quiz4, quiz5, quiz6, quiz7, quiz8, quiz9);
clickergrade = ClickerGrade (clickergrade, clicker);
break;
case 2:
DisplayGrades (asgnment, labtest, lecturetest, postlab, quiz, clickergrade);
break;
case 3:
grade = asgnment + labtest + lecturetest + postlab + quiz + clickergrade;
cout << "Your total grade is " << grade << "%" << endl;
if (grade <= 100 && grade >=90)
cout << "Letter grade A" << endl << endl;
else if (grade <= 89 &&grade >= 80)
cout << "Letter grade B" << endl << endl;
else if (grade <= 79 && grade >=70)
cout << "Letter grade C" << endl << endl;
else if (grade <= 69 && grade >=60)
cout << "Letter grade D, a little more!" << endl << endl;
else if (grade <= 59 && grade >=1)
cout << "Grade of F, you can do better!" << endl << endl;
else if (grade ==0)
cout << "Don't press 3 first!" << endl << endl;
}
}
return 0;
}
//Menu Options
int menu()
{
int choice;
cout << "Please select an option below." << endl << endl;
cout << "1. Enter Grades" << endl;
cout << "2. Display Grades" << endl;
cout << "3. Show Overall Grade" << endl;
cout << "4. Exit the Program"<< endl;
cout << "Enter your choice... ";
cin >> choice;
return choice;
}
//AssignmentGrade Function
float AssignmentGrade(float asgnment, float asgnment1, float asgnment2, float asgnment3, float asgnment4)
{
cout << "Okay, lets get started!" << endl;
cout << "Please enter your first assignment grade " << endl;
cin >> asgnment1;
cout << endl << "Enter your second assignment grade " << endl;
cin >> asgnment2;
cout << endl << "Enter your final assignment grade " << endl;
cin >> asgnment3;
asgnment = asgnment1*0.05 + asgnment2*0.05 + asgnment3 *0.05;
return asgnment;
}
// LabTestGrade Function
float LabTestGrade(float labtest, float labtest1, float labtest2, float labtest3)
{
cout << "Now you are going to enter your 3 lab test grades. " <<endl;
cout << "Please enter your first lab test score" <<endl;
cin >> labtest1;
cout << endl << "Now enter your second score" <<endl;
cin >> labtest2;
cout << endl << "Lastly, your final score" <<endl;
cin >> labtest3;
labtest = labtest1*0.10 + labtest2*0.10 + labtest3*0.10;
return labtest;
}
// LectureTestGrade Function
float LectureTestGrade (float lecturetest, float lecturetest1, float lecturetest2, float lecturetest3, float lecturetest4)
{
cout << "Next, you're going to enter your 4 Lecture Test grades." << endl;
cout << "Please enter your first lecture test grade" << endl;
cin >> lecturetest1;
cout << endl << "Now enter your second grade" << endl;
cin >> lecturetest2;
cout << endl << "Next, your third score" << endl;
cin >> lecturetest3;
cout << endl << "Finally, your fourth score" << endl;
cin >> lecturetest4;
lecturetest = lecturetest1*0.10 + lecturetest2*0.10 + lecturetest3*0.10 + lecturetest4*0.10;
return lecturetest;
}
// PostLabGrade Function
float PostLabGrade(float postlab, float p1, float p2, float p3, float p4, float p5, float p6, float p7, float p8, float p9)
{
cout << "Now, enter your 9 Post Lab grades" << endl;
cin >> p1 >> p2 >> p3 >> p4 >> p5 >> p6 >> p7 >> p8 >> p9;
postlab = p1*0.003 + p2*0.003 + p3*0.003 + p4*0.003 + p5*0.003 + p6*0.003 + p7*0.003 + p8*0.003 + p9*0.003;
return postlab;
}
// QuizGrade Function
float QuizGrade (float quiz, float quiz1, float quiz2, float quiz3, float quiz4, float quiz5, float quiz6, float quiz7, float quiz8, float quiz9)
{
cout << "9 more grades to enter, this time, please enter your quiz grades" << endl;
cin >> quiz1 >> quiz2 >> quiz3 >> quiz4 >> quiz5 >> quiz6 >> quiz7 >> quiz8 >> quiz9;
quiz = quiz1*0.004 + quiz2*0.004 + quiz3*0.004 + quiz4*0.004 + quiz5*0.004 + quiz6*0.004 + quiz7*0.004 + quiz8*0.004 + quiz9*0.004;
return quiz;
}
// ClickerGrade Function
float ClickerGrade (float clickergrade, float clicker)
{
cout << "Almost done! Now, enter your total clicker grade." << endl;
cin >> clicker;
cout << "Finished! Next..." << endl;
clickergrade = clicker*0.037;
return clickergrade;
}
// DisplayGrade Function
void DisplayGrades (float asgnment, float labtest, float lecturetest, float postlab, float quiz, float clickergrade)
{
cout << "Grades" << endl << endl;
cout << "Assignment";
cout << std::right << std::setw(7)<< asgnment << "%" << endl;
cout << "Lab Test";
cout << std::right << std::setw(9)<< labtest << "%" << endl;
cout << "Lecture";
cout << std::right << std::setw(10)<< lecturetest << "%" << endl;
cout << "Post Lab";
cout << std::right << std::setw(9)<< postlab << "%" << endl;
cout << "Quiz";
cout << std::right << std::setw(13)<< quiz << "%" << endl;
cout <<"Clicker";
cout << std::right << std::setw(10)<< clickergrade << "%" << endl;
}
// Valid grade function
bool Gradeisvalid (float score)
{
}
最佳答案
我没有编译,但这很关键:
if (choice == 4)
而不是 while()
int menu()
需要返回
一些东西这是作为 FirstStep 的 int main()
;) case 2
将只显示初始值,零。并检查我之前对整个编译的注释,然后它就可以工作了。
int main()
{
float asgnment = 0, asgnment1 = 0, asgnment2 = 0, asgnment3 = 0,
asgnment4 = 0, labtest = 0, labtest1 = 0, labtest2 = 0,
labtest3 = 0, lecturetest = 0, lecturetest1 = 0, lecturetest2 = 0,
lecturetest3 = 0, lecturetest4 = 0, postlab = 0, p1 = 0, p2 = 0, p3 = 0, p4 = 0,
p5 = 0, p6 = 0, p7 = 0, p8 = 0, p9 = 0, quiz = 0, quiz1 = 0, quiz2 = 0, quiz3 = 0, quiz4 = 0, quiz5 = 0,
quiz6 = 0, quiz7 = 0, quiz8 = 0, quiz9 = 0, clicker = 0, clickergrade = 0;
int choice;
choice = menu(); // let menu() return the entered int
switch(choice)
{
case 1:
AssignmentGrade(asgnment, asgnment1, asgnment2, asgnment3, asgnment4);
LabTestGrade(labtest, labtest1, labtest2, labtest3);
LectureTestGrade(lecturetest, lecturetest1, lecturetest2, lecturetest3, lecturetest4);
PostLabGrade(postlab, p1, p2, p3, p4, p5, p6, p7, p8, p9);
QuizGrade(quiz, quiz1, quiz2, quiz3, quiz4, quiz5, quiz6, quiz7, quiz8, quiz9);
ClickerGrade(clickergrade, clicker); break;
case 2:
DisplayGrades(asgnment, labtest, lecturetest, postlab, quiz, clickergrade);
}
return 0;
}
关于c++ - 菜单程序中的 bool 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35951222/
#include using namespace std; class C{ private: int value; public: C(){ value = 0;
这个问题已经有答案了: What is the difference between char a[] = ?string?; and char *p = ?string?;? (8 个回答) 已关闭
关闭。此题需要details or clarity 。目前不接受答案。 想要改进这个问题吗?通过 editing this post 添加详细信息并澄清问题. 已关闭 7 年前。 此帖子已于 8 个月
除了调试之外,是否有任何针对 c、c++ 或 c# 的测试工具,其工作原理类似于将独立函数复制粘贴到某个文本框,然后在其他文本框中输入参数? 最佳答案 也许您会考虑单元测试。我推荐你谷歌测试和谷歌模拟
我想在第二台显示器中移动一个窗口 (HWND)。问题是我尝试了很多方法,例如将分辨率加倍或输入负值,但它永远无法将窗口放在我的第二台显示器上。 关于如何在 C/C++/c# 中执行此操作的任何线索 最
我正在寻找 C/C++/C## 中不同类型 DES 的现有实现。我的运行平台是Windows XP/Vista/7。 我正在尝试编写一个 C# 程序,它将使用 DES 算法进行加密和解密。我需要一些实
很难说出这里要问什么。这个问题模棱两可、含糊不清、不完整、过于宽泛或夸夸其谈,无法以目前的形式得到合理的回答。如需帮助澄清此问题以便重新打开,visit the help center . 关闭 1
有没有办法强制将另一个 窗口置于顶部? 不是应用程序的窗口,而是另一个已经在系统上运行的窗口。 (Windows, C/C++/C#) 最佳答案 SetWindowPos(that_window_ha
假设您可以在 C/C++ 或 Csharp 之间做出选择,并且您打算在 Windows 和 Linux 服务器上运行同一服务器的多个实例,那么构建套接字服务器应用程序的最明智选择是什么? 最佳答案 如
你们能告诉我它们之间的区别吗? 顺便问一下,有什么叫C++库或C库的吗? 最佳答案 C++ 标准库 和 C 标准库 是 C++ 和 C 标准定义的库,提供给 C++ 和 C 程序使用。那是那些词的共同
下面的测试代码,我将输出信息放在注释中。我使用的是 gcc 4.8.5 和 Centos 7.2。 #include #include class C { public:
很难说出这里问的是什么。这个问题是含糊的、模糊的、不完整的、过于宽泛的或修辞性的,无法以目前的形式得到合理的回答。如需帮助澄清此问题以便重新打开它,visit the help center 。 已关
我的客户将使用名为 annoucement 的结构/类与客户通信。我想我会用 C++ 编写服务器。会有很多不同的类继承annoucement。我的问题是通过网络将这些类发送给客户端 我想也许我应该使用
我在 C# 中有以下函数: public Matrix ConcatDescriptors(IList> descriptors) { int cols = descriptors[0].Co
我有一个项目要编写一个函数来对某些数据执行某些操作。我可以用 C/C++ 编写代码,但我不想与雇主共享该函数的代码。相反,我只想让他有权在他自己的代码中调用该函数。是否可以?我想到了这两种方法 - 在
我使用的是编写糟糕的第 3 方 (C/C++) Api。我从托管代码(C++/CLI)中使用它。有时会出现“访问冲突错误”。这使整个应用程序崩溃。我知道我无法处理这些错误[如果指针访问非法内存位置等,
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 我们不允许提问寻求书籍、工具、软件库等的推荐。您可以编辑问题,以便用事实和引用来回答。 关闭 7 年前。
已关闭。此问题不符合Stack Overflow guidelines 。目前不接受答案。 要求我们推荐或查找工具、库或最喜欢的场外资源的问题对于 Stack Overflow 来说是偏离主题的,因为
我有一些 C 代码,将使用 P/Invoke 从 C# 调用。我正在尝试为这个 C 函数定义一个 C# 等效项。 SomeData* DoSomething(); struct SomeData {
这个问题已经有答案了: Why are these constructs using pre and post-increment undefined behavior? (14 个回答) 已关闭 6
我是一名优秀的程序员,十分优秀!