#include "stdafx.h"#include<iostream>#include<stdio.h>usingnamespacestd;
void minute(int t, int h);
int main()
{
int n,m,t,s,h;
cout << "please input \t minutes\t hour\t\n";
cin >> t >> h;
minute(t, h);
return0;
}
void minute(int t,int h)
{
cout << "Time :" << t << ":" << h;
}
4.1 Cout problem
int main()
{
char name[20], lname[10];
char k; int m;
cout << "what's your name?\t";
cin.getline(name, 20).get();
cout << "\nwhat's your last name?\t";
cin >> lname;//I don't know whether \n will exsit in the waiting place;cout << "\nwhat letter grade do you deserve?\t";
cin >> k;
cout << "waht's your age?\t";
cin >> m;
cout << "\nName\t" << lname << "," << name << endl;
cout << "Grade:\t" << k << endl;
cout << "Age:\t" << m << endl;
return0;
}
4.2 string2cout
#include "stdafx.h"#include<iostream>#include <string>#include<stdio.h>usingnamespacestd;
int main()
{
string name, lname;
char k; int m;
cout << "what's your name?\t";
getline(cin,name);// must use getline,in fact,we don't need to use get again.getline has getthe'\n'cout << "\nwhat's your last name?\t";
cin >> lname;//I don't know whether \n will exsit in the waiting place;cout << "\nwhat letter grade do you deserve?\t";
cin >> k;
cout << "waht's your age?\t";
cin >> m;
cout << "\nName\t" << lname << "," << name << endl;
cout << "Grade:\t" << k << endl;
cout << "Age:\t" << m << endl;
return0;
}
4.3 link
int main()
{
char name[20], lname[20];
char k; int m;
cout << "Enter your first name\t";
cin.getline(name,20);// must use getlinecout << "\nEnter your last name \t";
cin >> lname;
//remember using strcatstrcat(name, " , ");
strcat(name, lname);
cout << "using only one string\t\t" << name << endl;
return0;
}
4.4 link string
int main()
{
string name, lname;
char k; int m;
cout << "Enter your first name\t";
getline(cin,name);// must use getlinecout << "\nEnter your last name \t";
cin >> lname;
//remember using strcat
name = name + "," + lname;
cout << "using only one string\t\t" << name << endl;
return0;
}