标签:open sed names main break else 技术分享 reverse ice
#include <iostream> using namespace std; int Fill_array(double arr[], int n) { int count = 0; cout << "Enter your price: "<< endl; for(int i =0; i < n; i++) { cin >> arr[i]; if((i+1) == n) cout <<"Enough! You are a rich man!"<<endl; else if(!cin) break; count++; } return count; } void Show_array(const double arr[], int n) { cout << "Your price list below: " << endl; for (int i = 0; i < n; i++) cout << "Price #" << i+1 << ": "<< arr[i] << endl; } void Reverse_array(double arr[], int n) { cout << "OK! Your price is: " << endl; while(n--) { cout <<"$"<< arr[n] << endl; } } const int LEN = 5; int main() { double name[LEN]; int ct = Fill_array(name, LEN); cout << "There are " << ct << " cases of dirty money!"<<endl; Show_array(name, ct); Reverse_array(name, ct); }
sizeof(arr) / sizeof(double) 得到数组元素个数??
arr[LEN] == `\0`;
然后在for里用 i+1== LEN 来判断更容易理解,如果为true说明数组已经填满。
一会用指针做一遍。
fill array, show arrary , reverse_array
标签:open sed names main break else 技术分享 reverse ice
原文地址:http://www.cnblogs.com/TadGuo/p/7867724.html