三数比较大小有简化的方法吗?
我作业写了一个程序,但写得很复杂,想了解一下是否有方法把程序简化一下,谢谢大家的指导..要求:
Suppose viewers have voted and we have counted the votes.We want to know who the winner is.Write a program that asks for the number of votes each contestant these three numbers to determine the result of the contest.There are seven possible outcomes. Your program must determine which of the following is true and display it on the screen:
“Amanda wins”
“Ben wins”
“Chris wins”
“Amanda and Ben tie for first place”
“Amanda and Chris tie for first place”
“Ben and Chris tie for first place”
“Amanda, Ben and Chris all tie for first place”
程序如下:
#include <iostream>
using namespace std;
int main() {
int aVote = 0;
int bVote = 0;
int cVote = 0;
cout << "How many votes did Amanda received? ";
cin >> aVote;
cout << "How many votes did Ben received? ";
cin >> bVote;
cout << "Hoe many votes did Chris received? ";
cin >> cVote;
if (aVote > bVote) {
if (aVote > cVote)
cout << "Amanda wins" << endl;
else if (aVote = cVote)
cout << "Amanda and Chris tie for first place" <<endl;
else
cout << "Chris wins" << endl;
}
else if (aVote = bVote) {
if (aVote > cVote)
cout << "Amanda and Ben tie for first place" << endl;
else if (aVote = cVote)
cout << "Amanda, Ben and Chris all tie for first place" << endl;
else
cout << "Chris wins" << endl;
}
else {
if (bVote > cVote)
cout << "Ben wins" << endl;
else if (bVote =cVote)
cout << "Ben and Chris tie for first place" << endl;
else
cout << "Chris wins" << endl;
}
system("PAUSE");
return 0;
}