我如何在c++中使用带有字符串数组的for循环
How can i use for loop with String Array in c++
我在编译上述源代码时发现了错误。我想让循环到字符串的数组随着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++;
}
以下代码适用于您吗?
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;
}
相关文章:
- 将C#字符串数组传递给C++
- 如何为 C 型字符串数组编写 getter 和 setter?
- 有没有办法使用 strcpy 将字符串数组复制到另一个字符串或其他数组中?
- 尝试将 c 字符串数组与分隔符连接起来
- 将字符串数组传递给接受常量字符**的函数
- 返回 C++ 中的字符串数组
- 如何从COM模块中的函数返回字符串数组?
- 无法将字符串数组声明为类成员而不是字符 (C++)
- 删除字符串数组
- 如何将字符串数组返回到 java JNI
- 将字符串数组作为函数参数传递
- C++将字符串数组的元素存储到变量中
- 循环访问还包含未使用元素的字符串数组
- 字符串数组上的 sizeof 运算符以 C++ 为单位给出不同的输出
- 乘以字符串/数组和全局数组
- 递归二进制搜索与字符串数组
- 如何初始化一个标准::字符串数组?
- 无法在声明时使用初始值设定项列表初始化常量字符*/字符串数组的向量
- C++字符串数组的动态向量
- 给定一个等长字符串数组