Results 1 to 6 of 6
Thread: string
Hybrid View
-
3rd December 2013 20:08 #1
string
. ( ), - . , - .
:
Dev C++, Code Blocks. , "else nmp=tourists[0].names;", .Code:#include <iostream> using namespace std; struct Tourist { char names[50]; int age; }; int main() { Tourist tourists[30]; int n; cout<<"Enter number of tourists: "; cin>>n; cout<<endl; int i; for(i=0;i<n;i++) { cout<<"Enter three names: "; cin>>tourists[i].names; cout<<"Enter age: "; cin>>tourists[i].age; cout<<endl; } int max=tourists[0].age; string nmp; for(i=0;i<n;i++) { if(tourists[i].age>max) { max=tourists[i].age; nmp=tourists[i].names; } } cout<<"The oldest person is: "<<nmp; cout<<endl; system("pause>nul"); return 0; }ASRock B450M Pro4 / 5700X@4.5GHz / MSI RX 6600 XT Mech 2X / be quiet! Dark Rock 4 / 2x16GB FlareX 3200MHz CL16 / FSP Hydro G Pro 1000W / Samsung Odyssey G5 S27AG50
-
3rd December 2013 20:15 #2
nmp, -.
- , string-a
: XaMaB; . 0.42
In God we Trust (all others must submit a X.509 certificate). , ()
-
3rd December 2013 21:44 #3Registered User
Join Date: Sep:2013
Location: Bulgaria
Posts: 59
VS 2013 Express . "Enter three names: " 3 . cin, enter space 3 . . char string getline.
:
..: getline Enter, string- "\n". :Code:struct Tourist { string names; int age; }; // .... int main() { // ..... getline(cin, names); //.... }
Code://... int n; string names; //... cin>>n; /* Enter , , names "\n" */ cin.ignore(1, '\n'); //. names "\n" getline(cin,names); //...
-
3rd December 2013 22:26 #4
cin.getline, . string .
ASRock B450M Pro4 / 5700X@4.5GHz / MSI RX 6600 XT Mech 2X / be quiet! Dark Rock 4 / 2x16GB FlareX 3200MHz CL16 / FSP Hydro G Pro 1000W / Samsung Odyssey G5 S27AG50
-
4th December 2013 00:46 #5Registered User
Join Date: Dec:2007
Location: Sofia
Posts: 366
- , ( 'if' ).
-
6th December 2013 22:17 #6
max , ?
[edit] ,Code:#include <iostream> using namespace std; #define MAXT 30 #define MAXN 50 struct Tourist { char names[MAXN]; int age; }; int main() { Tourist tourists[MAXT]; int i, n, max=-1; do { cout<<"Enter number of tourists[1.."<<MAXT<<"]: "; cin>>n; cout<<endl; } while ((n<1)||(n>MAXT)); for(i=0;i<n;i++) { cout<<"Enter three names: "; cin.ignore(1, '\n'); cin.getline(tourists[i].names,999,'\n'); tourists[i].names[MAXN-1] = '\0'; cout<<"Enter age: "; cin>>tourists[i].age; cout<<endl; if (max<tourists[i].age) max = tourists[i].age; } cout<<"The oldest person(s) is: \n"; for (i=0;i<n;i++) if (tourists[i].age==max) cout<<tourists[i].names<<endl; system("pause>nul"); return 0; }
.Last edited by ined; 7th December 2013 at 23:16.
ASRock B85 Pro4, Pentium G3240, DD3 8GB/1333MHz, 120GB SSD + 1TB + 640GB HDD
Gigabyte GV-R657OC-1GI, CM B500, ASUS 24B1S1, LCD SAMSUNG SM931BW, 173




Reply With Quote
Lenovo ThinkPad 15 IdeaPad 15
5th May 2023, 22:16 in