当用户输入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。有问题?
我有两个数组。一个是卷号,另一个是卷号的总分。我必须按升序对卷号数组进行排序,同时保留分配给每个卷号的数据。我已经对数组进行了排序,但是如何根据卷号放置标记?
这是到目前为止的代码。
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) 当我输入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