| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1366 人关注过本帖
标题:三数比较大小有简化的方法吗?
取消只看楼主 加入收藏
young_zhou
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2012-2-24
结帖率:100%
收藏
已结贴  问题点数:10 回复次数:3 
三数比较大小有简化的方法吗?
我作业写了一个程序,但写得很复杂,想了解一下是否有方法把程序简化一下,谢谢大家的指导..
要求:
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;
}

搜索更多相关主题的帖子: determine following possible 
2012-02-24 04:39
young_zhou
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2012-2-24
收藏
得分:0 
因为在外国学习,所以作业要求都是英文的,如有需要可以看我的翻译,不过准确度就不能保证了
假设观众投票,我们把投票数算出来了.我们想知道谁是赢家.写一个程序,询问每个选手的票数,要求这三个数字来确定投票结果.共有七种可能结果。你的程序必须把正确的结果显示在屏幕上:

     “Amanda 赢”
     “Ben 赢”
     “Chris 赢”
     “Amanda 和 Ben 并列第一名”
     “Amanda 和 Chris 并列第一名”
     “Ben 和 Chris 并列第一名”
     “Amanda,Ben 和 Chris 并列第一名”
2012-02-24 04:58
young_zhou
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2012-2-24
收藏
得分:0 
请问有没有可以比较三数后直接返回最大的数,如果相等的话会全部显示?这样的话用switch就行了。。。
2012-02-25 08:14
young_zhou
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2012-2-24
收藏
得分:0 
还有,感觉c比c++要简练很多,为什么会说c++要高级点呢?
2012-02-25 08:30
快速回复:三数比较大小有简化的方法吗?
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.012417 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved