-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdrillp1t3.cpp
More file actions
97 lines (93 loc) · 2.71 KB
/
Copy pathdrillp1t3.cpp
File metadata and controls
97 lines (93 loc) · 2.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#include <iostream>
#include <string>
#include <ctype.h>
#include <stdlib.h>
#include <stdio.h>
#include <sstream>
using namespace std;
int debug =0;
int check_edat(double edat)
{
int edat_total;
double mesos;
if(debug ==1)cout << "Edat entrada (en mesos)= " << edat << "\n";
edat_total = edat/12;
mesos = edat/12-edat_total;
cout << "Tens " << edat_total << " anys i " << mesos << " mesos de vida\n" ;
return(0);
}
int check_nom(string nom, string letter)
{
int i=0;
int bolea=0;
int caracters = nom.length();
//cout << "Entro ?";
while (nom[i])
{
//if(!isalpha(nom[i])) bolea=1;
if(nom[i]>'0' && nom[i]<'9'){
if(debug ==1)cout << "És un número el caracter nom[i]= " << nom[i] ;
bolea=1;
return(bolea);
}
else{
if(debug ==1)cout << "No és número, m'ho menjo\n nom[i]= " << nom[i];
i++;
}
}
letter= letter + "\n Dear " + nom + ", ";
cout << "\nDear " << nom < ", "; // << ",\n amb una allarga de " << caracters << " caràcters \n";
return(bolea);
}
int main()
{
char friend_sex {0};
string nom;
string letter;
double edat;
int anys;
cout << "\n Enter the name of the person you want to write to ";
//while(check_nom(nom)!=0){
do{
cin >> nom;
}while(check_nom(nom,letter)!=0);
letter = letter + "\n\tHow are you ? I am fine. I miss you.\n";
string friend_name;
cout << "\n Insert friend name ";
cin >> friend_name;
letter = letter + "Have you seen " + friend_name + " latelly ?";
cout << "\nWhich sex are you ? \n m <- for male\n f <- for female\n ";
while (friend_sex !='m' && friend_sex !='f')
cin >> friend_sex;
if(friend_sex=='m') letter = letter + "If you see " + friend_name + " please ask him to call me.";
else if(friend_sex=='f') letter= letter + "If you see " + friend_name + "please ask her to call me.";
cout << "Insert how old are you";
int old_i;
string old;
cin >> old_i;
//old = itoa(old_i,old,3);
//snprintf(old, sizeof(old), "%d", old_i);
if(old_i <=0 or old_i > 109)
letter = "You are kidding me!!!";
if (old_i <12 ) {
old_i++;
//snprintf(old, sizeof(old), "%d", old_i);
//ostringstream convert; // stream used for the conversion
// convert << old_i;
// old= convert.str();
string old = static_cast<ostringstream*>( &(ostringstream() << old_i) )->str();
// letter = letter + "Next year you will be " + old;
// letter = letter + old;
}
if(old_i ==17) letter = letter + "\n Next year you will be able to vote.";
if (old_i >=70) letter = letter + "\nI hope you are enjoiering retirement";
letter = letter + "\n I hear you just had a brithday and you are " + old + " years old" ;
letter= letter + "\n\n\t\t\tYour Sincerely\n\n";
cout << "\n\n" << letter;
/*cout << "\nDóna'm la teva edat (amb mesos) ";
do{
cin >> edat;
}while(check_edat(edat) !=0);
cout << "\nPàgina 94 \n";*/
return (0);
}