Monday 15 May 2017

C++ Input and Output array using function

MAKE two arrays to input float values and characters from user and
displaying values of array element on screen.

#include<iostream>
using namespace std;
void floatdisplay(int size);
void chardisplay(int size);
int main(){
int size;
cout<<"enter the size of array that you want ";
cin>>size;
cout<<" enter 1 if you want float array \n and 2 if you want char array to be displayed "<<endl;
int choice;
cin>>choice;
switch(choice){
case 1:
floatdisplay(size);
break;
case 2:
chardisplay(size);
}
}
void floatdisplay(int size){

float a[20];
cout<<"enter total numbers "<<endl;
for(int x=0;x<size;x++){
cin>>a[x];
}
cout<<endl<<"now outputting what you entered ....."<<endl;
for(int x=0;x<size;x++){
cout<<a[x];
}
}
void chardisplay(int size){
char a[20];
cout<<"enter total characters "<<endl;
for(int x=0;x<size;x++){
cin>>a[x];
}
cout<<endl<<"now outputting what you entered ....."<<endl;
for(int x=0;x<size;x++){
cout<<a[x];
}
}







No comments:

Post a Comment