我在编译提到的源时发现错误。 我想用numberer数组循环到字符串数组增加。像是
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 :(得分: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;
}