小编scy*_*ypx的帖子

计算元音C ++

当用户输入10个字母时,程序应告诉他们其中有多少个元音。我写了这段代码:

while (count<10)
    {
        cin >> n;
        count++;
        if (n == 'A' || n == 'a' && n == 'E' || n == 'e' && n == 'I' || n == 'i' && n == 'O' || n == 'o' && n == 'U' || n == 'u')
            {
                total++;
            }
    }

cout <<  total << endl;
Run Code Online (Sandbox Code Playgroud)

即使用户输入了元音,也会产生输出0。有问题?

c++

2
推荐指数
1
解决办法
80
查看次数

排序并行数组

我有两个数组。一个是卷号,另一个是卷号的总分。我必须按升序对卷号数组进行排序,同时保留分配给每个卷号的数据。我已经对数组进行了排序,但是如何根据卷号放置标记?

这是到目前为止的代码。

int roll_num[5] = { 2, 4, 1, 6, 8 }, total_marks[5] = { 9, 7, 10, 8, 9 }, min=0, temp, size = 5;
    for (int i = 0; i <= size; i++)
    {
        min = i;
        for (int j = i + 1; j < size; j++)
        {
            if (roll_num[j] < roll_num[min])
            {
                min = j;
            }
        }
        swap(roll_num[i], roll_num[min]);
    }
    cout << "Roll No." << " " << "Total Marks" << endl;
    for (int i = …
Run Code Online (Sandbox Code Playgroud)

c++

0
推荐指数
1
解决办法
65
查看次数

这不是我想要的

当我输入0到9之间的任何数字时,我希望我的代码打印“您的汽车停在A区”。它正在接受输入,但是程序终止而没有进入if条件(我认为)

{  
    int value=0;
    cout<<"Enter car serial number"<<endl;
    cin>>value;
    if(value >= 48 && value <= 57)
    {
        cout<<"your car is parked in section Z"<<endl;
    }
}
Run Code Online (Sandbox Code Playgroud)

c++

-3
推荐指数
1
解决办法
109
查看次数

标签 统计

c++ ×3