2015-12-01 64 views
0

我編譯提到的源時發現錯誤。 我想循環到字符串數組增加numberer數組。像作爲我如何使用循環與C + +中的字符串數組

1 + st = 1st; 
2 + nd = 2nd; 
3 + rd = 3rd; 

我的代碼如下

#include <iostream> 
#include <stdio.h> 
#include <string> 
using namespace std; 

int main(){ 
int value=1; 
int ivalue; 
int sum=0; 
int average; 
int x,y; 
int count=0; 
string A[5]={"st","nd","rd","th","th"}; 


cout << "Enter loop limit : "; cin >> value ; 
cout<<endl; 
cout<<endl; 

for(x=0;x<=value-1;x++){ 
    for (x=0;x<=A[5];x++) 
     cout << "Enter "<<x+1<<A[0]<<" value : "; cin >> ivalue; 
     sum=sum+ivalue; 
     count++; 




    } 

回答

0

爲你做下面的代碼工作?

int main(){ 
    int value=1; 
    int ivalue; 
    int sum=0; 
    int count=0; 
    string A[5]={"st","nd","rd","th","th"}; 


    cout << "Enter loop limit : "; cin >> value ; 
    cout<<endl; 
    cout<<endl; 

    for(int x = 0; x <= value - 1; x++){ 
     cout << "Enter "<<x+1<<A[x]<<" value : "; 
     cin >> ivalue; 
     sum=sum+ivalue; 
     count++; 
    } 

    cout<<"Sum:"<<sum<<endl; 
} 
相關問題