还有其余的逻辑错误和语法错有有哪些.求解
#include
using namespace std;
void main()
{
int count = 0, count1 = 0, count2 = 0, count3 = 0;
mark = -9;
while (mark != -9)
{
cout << "insert marks of students in your class, enter -9 to stop entering";
cin >> mark;
count++;
if (mark >= 0 && mark <= 60);
count1 = count1 + 1;
else if (mark >= 61 && mark <= 70);
count2 = count2 + 1;
else if (mark >= 71 && mark <= 100);
count3 = count3 + 1;
}
cout <<"Report of MTS3013 course" << endl;
cout <<"Mark" << count << endl << endl;
cout << "0-60" << "\t\t\t\t" << count1 << endl;
cout << "61-70" << "\t\t\t\t" << count2 << endl;
cout << "71-100" << "\t\t\t\t" << count3 << endl<< endl << endl;
cout << "End of program";
}
建议如下更改,否则count的值是不对的,把-9也算进去了
#include <iostream>
using namespace std;
void main()
{
int count = 0, count1 = 0, count2 = 0, count3 = 0;
int mark=0;
while (1)
{
cout << "insert marks of students in your class, enter -9 to stop entering\n";
cin >> mark;
if(mark == -9)
break;
count++;
if (mark >= 0 && mark <= 60)
count1 = count1 + 1;
else if (mark >= 61 && mark <= 70)//;
count2 = count2 + 1;
else if (mark >= 71 && mark <= 100)//;
count3 = count3 + 1;
}
cout <<"Report of MTS3013 course" << endl;
cout <<"Mark " << count << endl << endl;
cout << "0-60" << "\t\t\t\t" << count1 << endl;
cout << "61-70" << "\t\t\t\t" << count2 << endl;
cout << "71-100" << "\t\t\t\t" << count3 << endl<< endl << endl;
cout << "End of program";
}
代码修改如下:(问题在代码中标注)
#include <iostream>
using namespace std;
void main()
{
int count = 0, count1 = 0, count2 = 0, count3 = 0;
int mark = -9; //修改1,添加变量类型
while (1)
{
cout << "insert marks of students in your class, enter -9 to stop entering";
cin >> mark;
if(mark ==-9) break;
count++;
if (mark >= 0 && mark <= 60)//; //这里多了一个分号
count1 = count1 + 1;
else if (mark >= 61 && mark <= 70)//;//这里多了一个分号
count2 = count2 + 1;
else if (mark >= 71 && mark <= 100)//;//这里多了一个分号
count3 = count3 + 1;
}
cout <<"Report of MTS3013 course" << endl;
cout <<"Mark" << count << endl << endl;
cout << "0-60" << "\t\t\t\t" << count1 << endl;
cout << "61-70" << "\t\t\t\t" << count2 << endl;
cout << "71-100" << "\t\t\t\t" << count3 << endl<< endl << endl;
cout << "End of program";
}
#include <iostream>
using namespace std;
void main()
{
int count = 0, count1 = 0, count2 = 0, count3 = 0;
int mark=0;//mark = -9;缺少类型,并且初始化不能为-9,否则不执行循环
while (mark != -9)
{
cout << "insert marks of students in your class, enter -9 to stop entering\n";
cin >> mark;
count++;
if (mark >= 0 && mark <= 60)//;多个个分号,下同
count1 = count1 + 1;
else if (mark >= 61 && mark <= 70)//;
count2 = count2 + 1;
else if (mark >= 71 && mark <= 100)//;
count3 = count3 + 1;
}
cout <<"Report of MTS3013 course" << endl;
cout <<"Mark" << count << endl << endl;
cout << "0-60" << "\t\t\t\t" << count1 << endl;
cout << "61-70" << "\t\t\t\t" << count2 << endl;
cout << "71-100" << "\t\t\t\t" << count3 << endl<< endl << endl;
cout << "End of program";
}