#include <iostream>
#include <string>
#include <sstream>
#include <unistd.h>
using namespace std;
int main()
{
int score;
string name, sco;
cout<<"Hello! I am Mrs. Marian! I am the administratress of this humble website!"<<'\n';
cout<<"This website is kindly brought to you by our Prime Minister Candry Veneroth."<<'\n';
cout<<"This is the 'National School Grading System', or the NSGS, to help you see if your student fails or not."<<'\n';
cout<<"The first thing you have to do is type the student's name: "<<'\n';
getline(cin,name);
cout<<"Great! Now please enter "<<name<<"'s correct answers in the National Education Test: ";
getline(cin,sco);
stringstream(sco)>>score;
cout<<"The NET (National Education Test) has a total score of 180 with 150 questions with each question having a score of 1.2"<<'\n';
cout<<"Loading data"<<'\n';
if (score*1.2<90, score*1.2>=0)
{
cout<<"The student "<<name<<" has NOT PASSED, with a score of "<<score*1.2<<". I am sorry, and hope the best for next time.";
}
else if (score*1.2<180, score*1.2>=90)
{
cout<<"CONGRATULATIONS!"<<'\n'<<"The student "<<name<<" has PASSED, with a score of "<<score*1.2<<". Once again, congratulations!";
}
else if (score*1.2==180)
{
cout<<"CONGRATULATIONS!!!"<<'\n'<<"The student "<<name<<" has PASSED with a perfect score of "<<score*1.2<<". You will have a bright future ahead of you, "<<name<<". And I hope you for a bright future";
}
else if (score*1.2>180, score*1.2<0)
{
cout<<"This is invalid, and entering an invalid score in the NSGS is considered an act of malice against the students of Lantreind and is illegal according to the National Education Test Act (NETA) verse 5:";
cout<<'\n'<<"'For thee who dare to destroy a student's scores, shall be convicted in the name of the Veneroth name.'"<<'\n'<<"You have been warned.";
}
}
好的,我!我是新手!练习'if else'功能..我希望能够这样做:
我一直在修改代码,起初,第一个和第二个'if和if else(s)'没有'逗号后的代码'。所以,即使得分是180或-897或1131,它仍然会说他们(通过/不通过),完全忽略第3和第4'如果别的话。'
哦!而且,我想“暂停(1)”显而易见,为什么我把#include,但它不起作用!消息是=
错误:函数'int pause()'
的参数太多
我真的不知道如何解决这个问题,我希望任何人都可以帮我弄清楚出了什么问题以及如何解决它并让它按照预期的方式进行。
谢谢!
此致 Crunch Gum
答案 0 :(得分:3)
&&
运算符。可能的解决方法:
#include <iostream>
#include <string>
#include <sstream>
#include <unistd.h>
using namespace std;
int main()
{
int score;
string name, sco;
cout<<"Hello! I am Mrs. Marian! I am the administratress of this humble website!"<<'\n';
cout<<"This website is kindly brought to you by our Prime Minister Candry Veneroth."<<'\n';
cout<<"This is the 'National School Grading System', or the NSGS, to help you see if your student fails or not."<<'\n';
cout<<"The first thing you have to do is type the student's name: "<<'\n';
getline(cin,name);
cout<<"Great! Now please enter "<<name<<"'s correct answers in the National Education Test: ";
getline(cin,sco);
stringstream(sco)>>score;
cout<<"The NET (National Education Test) has a total score of 180 with 150 questions with each question having a score of 1.2"<<'\n';
cout<<"Loading data"<<'\n';
int mscore = score * 12;
if (mscore<900 && mscore>=0)
{
cout<<"The student "<<name<<" has NOT PASSED, with a score of "<<score*1.2<<". I am sorry, and hope the best for next time.";
}
else if (mscore<1800 && mscore>=900)
{
cout<<"CONGRATULATIONS!"<<'\n'<<"The student "<<name<<" has PASSED, with a score of "<<score*1.2<<". Once again, congratulations!";
}
else if (mscore==1800)
{
cout<<"CONGRATULATIONS!!!"<<'\n'<<"The student "<<name<<" has PASSED with a perfect score of "<<score*1.2<<". You will have a bright future ahead of you, "<<name<<". And I hope you for a bright future";
}
else
{
cout<<"This is invalid, and entering an invalid score in the NSGS is considered an act of malice against the students of Lantreind and is illegal according to the National Education Test Act (NETA) verse 5:";
cout<<'\n'<<"'For thee who dare to destroy a student's scores, shall be convicted in the name of the Veneroth name.'"<<'\n'<<"You have been warned.";
}
}
答案 1 :(得分:0)
更改:if (score*1.2<90, score*1.2>=0)
使用:if (score*1.2<90 && score*1.2>=0)
既然你想要完成这两个条件
更改:else if (score*1.2<180, score*1.2>=90)
使用:else if (score*1.2<180 && score*1.2>=90)
既然你想要完成这两个条件
更改:else if (score*1.2>180, score*1.2<0)
使用:else if (score*1.2>180 || score*1.2<0)
既然你想完成这两个条件之一