查看: 759|回复: 3
|
求助~C++~新手
[复制链接]
|
|
我想求助是:
我的2道问题,如果都是先给他invalid input先,才回答正确答案,应该是4+4=8分才对,可是我的一上述方法(先给他invalid input 后,才回答正确答),最后我才拿到4分罢了,就是拿不到8分~~敬请帮忙。。。
#include <iostream>
#include <string>
using namespace std;
int main()
{
string name;
char ans;
int mark = 0;
cout << "****************************************" << endl;
cout << "Welcome To Questionnaire About Oral Health Care" << endl;
cout << "****************************************" << endl;
cout << "Please Enter Your Name:" << endl;
getline(cin, name);
cout << "**************************************** " << endl;
cout << "1)What do you use for cleaning your teeth?" << endl;
cout << "a.Brush + toothpaste only\nb.Brush + toothpaste + dental floss" << endl;
cin >> ans;
if (ans == 'a' || ans == 'b' || ans == 'A' || ans == 'B')
{
if ((ans == 'b') || (ans == 'B'))
{
mark += 4;
}
}
else
{
do
{
mark = +0;
cout << "Invalid input!" << endl;
cout << "Please enter a or b" << endl;
cout << "Try again : " << endl;
cin >> ans;
if ((ans == 'b') || (ans == 'B'))
{
mark += 4;
}
}
while (ans != 'a' && ans != 'b' && ans != 'A' && ans != 'B');
}
cout << "2)How often do you brush your teeth each day?" << endl;
cout << "a.Twice a day\nb.Once a day" << endl;
cin >> ans;
if (ans == 'a' || ans == 'b' || ans == 'A' || ans == 'B')
{
if ((ans == 'a') || (ans == 'A'))
{
mark = +4;
}
}
else
{
do
{
mark = +0;
cout << "Invalid input!" << endl;
cout << "Please enter a or b" << endl;
cout << "Try again : " << endl;
cin >> ans;
if ((ans == 'a') || (ans == 'A'))
{
mark = +4;
}
}
while (ans != 'a' && ans != 'b' && ans != 'A' && ans != 'B');
}
cout << "\nThe total mark is: " << endl;
cout << mark << endl;
if (mark >= 0 && mark <= 48)
{
cout << "You're FAILED!" << endl;
}
else if (mark >= 48 && mark <= 80)
{
cout << "Not bad!" << endl;
}
else
{
cout << "You're EXCELLENT!" << endl;
}
return 0;
}
|
|
|
|
|
|
|
|

楼主 |
发表于 10-4-2016 09:00 PM
|
显示全部楼层
请无视几多分fail几多分excellent那些= =! 谢谢 |
|
|
|
|
|
|
|

楼主 |
发表于 11-4-2016 09:19 AM
|
显示全部楼层
解决了,谢谢.gif) |
|
|
|
|
|
|
|
发表于 24-4-2016 08:22 PM
|
显示全部楼层
|
|
|
|
|
|
| |
本周最热论坛帖子
|