小马同学要努力△ 2022-10-17 21:27 采纳率: 77.3%
浏览 34

C语言scanf switch

scanf带grade的那一行代码为什么会报错?
报错是scanf未传递足够的参数,能不能细讲一下谢谢
#include<stdio.h>
int main()
{
int a;
printf("请输入1或2(等级转分数为1,分数转等级为2)\n");
scanf_s("%d", &a);
char grade;
if (a == 1) {

    printf("请输入等级:\n");
    scanf_s("%c",&grade,sizeof(grade));

    switch (grade)
    {
    case 'A':
        printf("对应分数为90-100");
        break;
    case 'B':
        printf("对应分数为80-89");
        break;
    case 'C':
        printf("对应分数为70-79");
        break;
    case 'D':
        printf("对应分数为60-69");
        break;
    case 'E':
        printf("对应分数为60分以下");
    default:
        printf("enter date error");

    }

}
else
{
    int a,b;
    printf("请输入你的分数:\n");
    scanf_s("%d", &a);
    b = a/10;
    switch (b)
    {
        case 10:
        case 9:printf("A\n");
            break;
        case 8:printf("B\n");
            break;
        case 7:printf("C\n");
            break;
        case 6:printf("D\n");
            break;
        case 5:
        case 4:
        case 3:
        case 2:
        case 1:
        case 0:printf("E\n");
            break;
        default:printf("enter date error");

    }





}
return 0;#include<stdio.h>

int main()
{
int a;
printf("请输入1或2(等级转分数为1,分数转等级为2)\n");
scanf_s("%d", &a);
char grade;
if (a == 1) {

    printf("请输入等级:\n");
    scanf_s("%c",&grade,sizeof(grade));

    switch (grade)
    {
    case 'A':
        printf("对应分数为90-100");
        break;
    case 'B':
        printf("对应分数为80-89");
        break;
    case 'C':
        printf("对应分数为70-79");
        break;
    case 'D':
        printf("对应分数为60-69");
        break;
    case 'E':
        printf("对应分数为60分以下");
    default:
        printf("enter date error");

    }

}
else
{
    int a,b;
    printf("请输入你的分数:\n");
    scanf_s("%d", &a);
    b = a/10;
    switch (b)
    {
        case 10:
        case 9:printf("A\n");
            break;
        case 8:printf("B\n");
            break;
        case 7:printf("C\n");
            break;
        case 6:printf("D\n");
            break;
        case 5:
        case 4:
        case 3:
        case 2:
        case 1:
        case 0:printf("E\n");
            break;
        default:printf("enter date error");

    }





}
return 0;#include<stdio.h>

int main()
{
int a;
printf("请输入1或2(等级转分数为1,分数转等级为2)\n");
scanf_s("%d", &a);
char grade;
if (a == 1) {

    printf("请输入等级:\n");
    scanf_s("%c",&grade,sizeof(grade));

    switch (grade)
    {
    case 'A':
        printf("对应分数为90-100");
        break;
    case 'B':
        printf("对应分数为80-89");
        break;
    case 'C':
        printf("对应分数为70-79");
        break;
    case 'D':
        printf("对应分数为60-69");
        break;
    case 'E':
        printf("对应分数为60分以下");
    default:
        printf("enter date error");

    }

}
else
{
    int a,b;
    printf("请输入你的分数:\n");
    scanf_s("%d", &a);
    b = a/10;
    switch (b)
    {
        case 10:
        case 9:printf("A\n");
            break;
        case 8:printf("B\n");
            break;
        case 7:printf("C\n");
            break;
        case 6:printf("D\n");
            break;
        case 5:
        case 4:
        case 3:
        case 2:
        case 1:
        case 0:printf("E\n");
            break;
        default:printf("enter date error");

    }





}
return 0;#include<stdio.h>

int main()
{
int a;
printf("请输入1或2(等级转分数为1,分数转等级为2)\n");
scanf_s("%d", &a);
char grade;
if (a == 1) {

    printf("请输入等级:\n");
    scanf_s("%c",&grade,sizeof(grade));

    switch (grade)
    {
    case 'A':
        printf("对应分数为90-100");
        break;
    case 'B':
        printf("对应分数为80-89");
        break;
    case 'C':
        printf("对应分数为70-79");
        break;
    case 'D':
        printf("对应分数为60-69");
        break;
    case 'E':
        printf("对应分数为60分以下");
    default:
        printf("enter date error");

    }

}
else
{
    int a,b;
    printf("请输入你的分数:\n");
    scanf_s("%d", &a);
    b = a/10;
    switch (b)
    {
        case 10:
        case 9:printf("A\n");
            break;
        case 8:printf("B\n");
            break;
        case 7:printf("C\n");
            break;
        case 6:printf("D\n");
            break;
        case 5:
        case 4:
        case 3:
        case 2:
        case 1:
        case 0:printf("E\n");
            break;
        default:printf("enter date error");

    }





}
return 0;#include<stdio.h>

int main()
{
int a;
printf("请输入1或2(等级转分数为1,分数转等级为2)\n");
scanf_s("%d", &a);
char grade;
if (a == 1) {

    printf("请输入等级:\n");
    scanf_s("%c",&grade,sizeof(grade));

    switch (grade)
    {
    case 'A':
        printf("对应分数为90-100");
        break;
    case 'B':
        printf("对应分数为80-89");
        break;
    case 'C':
        printf("对应分数为70-79");
        break;
    case 'D':
        printf("对应分数为60-69");
        break;
    case 'E':
        printf("对应分数为60分以下");
    default:
        printf("enter date error");

    }

}
else
{
    int a,b;
    printf("请输入你的分数:\n");
    scanf_s("%d", &a);
    b = a/10;
    switch (b)
    {
        case 10:
        case 9:printf("A\n");
            break;
        case 8:printf("B\n");
            break;
        case 7:printf("C\n");
            break;
        case 6:printf("D\n");
            break;
        case 5:
        case 4:
        case 3:
        case 2:
        case 1:
        case 0:printf("E\n");
            break;
        default:printf("enter date error");

    }





}
return 0;#include<stdio.h>

int main()
{
int a;
printf("请输入1或2(等级转分数为1,分数转等级为2)\n");
scanf_s("%d", &a);
char grade;
if (a == 1) {

    printf("请输入等级:\n");
    scanf_s("%c",&grade,sizeof(grade));

    switch (grade)
    {
    case 'A':
        printf("对应分数为90-100");
        break;
    case 'B':
        printf("对应分数为80-89");
        break;
    case 'C':
        printf("对应分数为70-79");
        break;
    case 'D':
        printf("对应分数为60-69");
        break;
    case 'E':
        printf("对应分数为60分以下");
    default:
        printf("enter date error");

    }

}
else
{
    int a,b;
    printf("请输入你的分数:\n");
    scanf_s("%d", &a);
    b = a/10;
    switch (b)
    {
        case 10:
        case 9:printf("A\n");
            break;
        case 8:printf("B\n");
            break;
        case 7:printf("C\n");
            break;
        case 6:printf("D\n");
            break;
        case 5:
        case 4:
        case 3:
        case 2:
        case 1:
        case 0:printf("E\n");
            break;
        default:printf("enter date error");

    }





}
return 0;#include<stdio.h>

int main()
{
int a;
printf("请输入1或2(等级转分数为1,分数转等级为2)\n");
scanf_s("%d", &a);
char grade;
if (a == 1) {

    printf("请输入等级:\n");
    scanf_s("%c",&grade,sizeof(grade));

    switch (grade)
    {
    case 'A':
        printf("对应分数为90-100");
        break;
    case 'B':
        printf("对应分数为80-89");
        break;
    case 'C':
        printf("对应分数为70-79");
        break;
    case 'D':
        printf("对应分数为60-69");
        break;
    case 'E':
        printf("对应分数为60分以下");
    default:
        printf("enter date error");

    }

}
else
{
    int a,b;
    printf("请输入你的分数:\n");
    scanf_s("%d", &a);
    b = a/10;
    switch (b)
    {
        case 10:
        case 9:printf("A\n");
            break;
        case 8:printf("B\n");
            break;
        case 7:printf("C\n");
            break;
        case 6:printf("D\n");
            break;
        case 5:
        case 4:
        case 3:
        case 2:
        case 1:
        case 0:printf("E\n");
            break;
        default:printf("enter date error");

    }





}
return 0;#include<stdio.h>

int main()
{
int a;
printf("请输入1或2(等级转分数为1,分数转等级为2)\n");
scanf_s("%d", &a);
char grade;
if (a == 1) {

    printf("请输入等级:\n");
    scanf_s("%c",&grade,sizeof(grade));

    switch (grade)
    {
    case 'A':
        printf("对应分数为90-100");
        break;
    case 'B':
        printf("对应分数为80-89");
        break;
    case 'C':
        printf("对应分数为70-79");
        break;
    case 'D':
        printf("对应分数为60-69");
        break;
    case 'E':
        printf("对应分数为60分以下");
    default:
        printf("enter date error");

    }

}
else
{
    int a,b;
    printf("请输入你的分数:\n");
    scanf_s("%d", &a);
    b = a/10;
    switch (b)
    {
        case 10:
        case 9:printf("A\n");
            break;
        case 8:printf("B\n");
            break;
        case 7:printf("C\n");
            break;
        case 6:printf("D\n");
            break;
        case 5:
        case 4:
        case 3:
        case 2:
        case 1:
        case 0:printf("E\n");
            break;
        default:printf("enter date error");

    }





}
return 0;#include<stdio.h>

int main()
{
int a;
printf("请输入1或2(等级转分数为1,分数转等级为2)\n");
scanf_s("%d", &a);
char grade;
if (a == 1) {

    printf("请输入等级:\n");
    scanf_s("%c",&grade,sizeof(grade));

    switch (grade)
    {
    case 'A':
        printf("对应分数为90-100");
        break;
    case 'B':
        printf("对应分数为80-89");
        break;
    case 'C':
        printf("对应分数为70-79");
        break;
    case 'D':
        printf("对应分数为60-69");
        break;
    case 'E':
        printf("对应分数为60分以下");
    default:
        printf("enter date error");

    }

}
else
{
    int a,b;
    printf("请输入你的分数:\n");
    scanf_s("%d", &a);
    b = a/10;
    switch (b)
    {
        case 10:
        case 9:printf("A\n");
            break;
        case 8:printf("B\n");
            break;
        case 7:printf("C\n");
            break;
        case 6:printf("D\n");
            break;
        case 5:
        case 4:
        case 3:
        case 2:
        case 1:
        case 0:printf("E\n");
            break;
        default:printf("enter date error");

    }





}
return 0;#include<stdio.h>

int main()
{
int a;
printf("请输入1或2(等级转分数为1,分数转等级为2)\n");
scanf_s("%d", &a);
char grade;
if (a == 1) {

    printf("请输入等级:\n");
    scanf_s("%c",&grade,sizeof(grade));

    switch (grade)
    {
    case 'A':
        printf("对应分数为90-100");
        break;
    case 'B':
        printf("对应分数为80-89");
        break;
    case 'C':
        printf("对应分数为70-79");
        break;
    case 'D':
        printf("对应分数为60-69");
        break;
    case 'E':
        printf("对应分数为60分以下");
    default:
        printf("enter date error");

    }

}
else
{
    int a,b;
    printf("请输入你的分数:\n");
    scanf_s("%d", &a);
    b = a/10;
    switch (b)
    {
        case 10:
        case 9:printf("A\n");
            break;
        case 8:printf("B\n");
            break;
        case 7:printf("C\n");
            break;
        case 6:printf("D\n");
            break;
        case 5:
        case 4:
        case 3:
        case 2:
        case 1:
        case 0:printf("E\n");
            break;
        default:printf("enter date error");

    }
  • 写回答

3条回答 默认 最新

  • X-道至简 2022-10-17 21:47
    关注

    scanf_s("%c",&grade,sizeof(grade));
    去掉sizeof那个
    scanf_s("%c",&grade);

    评论

报告相同问题?

问题事件

  • 创建了问题 10月17日

悬赏问题

  • ¥100 需要跳转番茄畅听app的adb命令
  • ¥50 寻找一位有逆向游戏盾sdk 应用程序经验的技术
  • ¥15 请问有用MZmine处理 “Waters SYNAPT G2-Si QTOF质谱仪在MSE模式下采集的非靶向数据” 的分析教程吗
  • ¥50 opencv4nodejs 如何安装
  • ¥15 adb push异常 adb: error: 1409-byte write failed: Invalid argument
  • ¥15 nginx反向代理获取ip,java获取真实ip
  • ¥15 eda:门禁系统设计
  • ¥50 如何使用js去调用vscode-js-debugger的方法去调试网页
  • ¥15 376.1电表主站通信协议下发指令全被否认问题
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证