小编gos*_*tag的帖子

返回数组中最小元素的索引

我试图用整数数组中的最小元素返回索引.我错过了什么吗?在我将整数放入后,它不会返回索引.

更新:int main()关于数据堆栈被破坏,我得到一个错误.谢谢.我的代码如下:

#include <iostream>
#include <conio.h>

using namespace std;

int indexofSmallestElement(double array[], int size);

int main()
{    
int size = 10; 
double array[10];

for (int i = 0; i <= size; i++)
{
    cout << "Enter an integer: " << endl;
    cin >> array[i];
}

indexofSmallestElement(array, size);
}

int indexofSmallestElement(double array[], int size)
{
int index = 0;

if (size != 1)
{

    int n = array[0];
    for (int i = 1; i < size; i++)
    { …
Run Code Online (Sandbox Code Playgroud)

c++ arrays indexing

6
推荐指数
2
解决办法
2万
查看次数

我的if语句究竟出了什么问题?

我尝试了不同的方法来布置我的if语句,我甚至试过嵌套的if语句.我得到了相同的结果.除了显示我的代码之外,我不确定是否有任何方式可以提出我的问题.

#include <iostream>
#include <conio.h>
#include <string>

using namespace std;

int main()
{
char playerOne, playerTwo;

cout<<"ROCK PAPER SCISSORS!"<<endl;
cout<<"Enter P for Paper"<<endl;
cout<<"Enter R for Rock"<<endl;
cout<<"Enter S for Scissors"<<endl;

cout<<"Player One enter your choice: ";
cin>>playerOne;

cout<<"Player Two enter your choice: ";
cin>>playerTwo;

if ((playerOne = 'R') && (playerTwo = 'R'))
    cout<<"Both players played same hand";
else if ((playerOne = 'R') && (playerTwo = 'P'))
    cout<<"Player Two wins!";
else if ((playerOne = 'R') && (playerTwo = 'S'))
    cout<<"Player …
Run Code Online (Sandbox Code Playgroud)

c++

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

标签 统计

c++ ×2

arrays ×1

indexing ×1