2011-04-26 20 views
-5
#include <iostream> 

using namespace std; 

float sum(float a,float b); 

float subs(float a, float b); 

float multiple(float a, float b); 

float division(float a, float b); 

int main() 

{//main 

    int a,b; 

    char o ; 
    cout<<"input your calculation with operation (+,-,/,*) such as 5+6 : /n "; 
    cin >> a >> o >> b ; 
    switch('o') 
    { 
    case '+': 

     sum(float a, float b); 
     break; 

    case '-': 

     subs(float a, float b); 
     break; 

    case '*': 

     multiple(float a, float b); 
     break; 

    case '/': 

     division(float a, float b); 
     break; 

    default : 
     cout << "error, try again " <<endl; 

    } 
    return 0; 
}//main 

float sum(float a,float b) 
{//sum 

    float total= a+b; 
    return total; 
}//sum 

float subs(float a, float b) 
{//subs 

    float total=a-b; 
    return total; 
}//subs  

float multiple(float a, float b) 
{//multiple 

    float total=a*b; 
    return total; 
}//multiple 

float division(float a, float b) 
{//division 

    float total=a/b; 
+3

做什麼你的代碼的一部分,並不如預期的作品?這是功課嗎? – 2011-04-26 14:25:03

+2

我不知道。你的代碼有哪些*錯誤? (它是編譯器錯誤,運行時崩潰還是別的?) – 2011-04-26 14:25:28

+0

一個猜測:我沒有看到任何可以顯示或以其他方式使用操作結果的東西。函數的返回值被忽略。你打算打印結果嗎? – 2011-04-26 14:49:26

回答

7

從表面上看,最後缺少一個大括號。在操作上,您的switch語句打開一個常量'o',而不是變量o。

+0

編譯器表示第18,23,28,33行有錯誤: 函數main()中的表達式語法 – Quark92 2011-04-26 15:43:12

0

變化:

switch('o') 

switch(o)