为什么会出现错误sh:1:暂停:找不到

时间:2019-02-11 05:46:33

标签: c++

为什么会出现错误sh:1:暂停:未找到?我是我的程序。

我可以正确使用动态数组吗?

基本上,以下程序需要收集一些人的姓名及其高分,然后显示结果。

以下是我的代码:

#include <iostream>
#include <iomanip>
#include <string>

using namespace std;
//function declaration//
int voteamount(int list[], int size);
int wintally(int list[], int size);
//main start//
int main()
{
    //variables//
    string candidates[5];
    int votes[5] = {0};
    int totalVotes;
    int i;
    cout << fixed << showpoint;
    //decimal precision//
    cout << setprecision(2);
    cout << "Enter candidate's name and the votes received by "
         <<"the candidate." << endl;

    for (i = 0; i < 5; i++)
        //user input candidates//
        cin >> candidates[i] >> votes[i];
    //calculate sum of votes//
    totalVotes = voteamount(votes, 5);
    //print votes received//
    cout << "Candidate    Votes Received   % of Total Votes" << endl;
    for (i = 0; i < 5; i++)
        cout << left << setw(10) << candidates[i]
             << right << " " << setw(10) << votes[i] << "   " << setw(15)
             << (static_cast<double>(votes[i]) / static_cast<double>(totalVotes)) * 100
             << endl;
    cout << "Total            " << totalVotes << endl;
    cout << "The Winner of the Election is "
         << candidates[wintally(votes, 5)]
         << "." << endl;
   system("PAUSE");
    return 0;
}
//method for vote amount//
int voteamount(int list[], int size)
{
   int sum = 0;
   for (int i = 0; i < size; i++)
        //calculates the sum of votes//
       sum = sum + list[i];
    //returns the value//
   return sum;
}
//method for winner tally//
int wintally(int list[], int size)
{
    int winInd = 0;

    for (int i = 0; i < size; i++)
        //checks list with the index value//
        if (list[i] > list[winInd])
            winInd = i;
    return winInd;
}

0 个答案:

没有答案