Thank you, Salem, anon.
Salem, if you don't mind could you please help me to understand the bold phrase in your signature: If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
What does the phrase "of undefined behaviour" mean here? Thanks.
Probably I will get to see the benefit of the structure syntax later when I run into complex problems.
I'm getting these errors for the code given below:
Code:
expected '}' before 'else'
expected 'while' before 'v'
expected '(' before 'v'
'v' was not declared in this scope
expected ')' before ';' token
expected unqualified-id before 'while'
expected constructor, destructor, or type conversion before '<<' token
expected constructor, destructor, or type conversion before '<<' token
expected unqualified-id before 'return'
expected constructor, destructor, or type conversion before '(' token
expected declaration before '}' token
I understand most of the errors have to do with the problem of declaring variables within the block of the do/while loop. Correct? But I don't get the reason for the first bold error above. Arn't I supposed to enclose the if block within the braces (else if and else are part of the if statement (or, condition) ). Please help me. Thanks.
Code:
// sorting out telephone numbers from different cities
#include <iostream>
#include <cstdlib>
using namespace std;
////////////////////////////////////////////////////////
struct teldata
{ int countrycode, citycode, number;};
////////////////////////////////////////////////////////
int main()
{
teldata telnumber;
do
{
cout << "enter the details\n";
cout << "enter country code: "; cin >> telnumber.countrycode;
cout << "enter city code: "; cin >> telnumber.citycode;
cout << "enter the number: "; cin >> telnumber.number;
int Num4rmCity1=0, Num4rmCity2=0, Num4rmOtherCity;
if (telnumber.citycode == 111)
{
Num4rmCity1 = Num4rmCity1++;
else if (telnumber.citycode == 222)
Num4rmCity2 = Num4rmCity2++;
else
Num4rmOtherCity = Num4rmOtherCity++;
}
char v;
cout << "Do you want to enter another number: "; cin >> v;
}
while (v != 'n')
cout << "tel numbers from City 1: " << Num4rmCity1 <<endl;
cout << "tel numbers from City 2: " << Num4rmCity2 <<endl;
cout << "tel numbers from other cities: " << Num4rmOthercity <<endl;
return 0;
system ("pause");
}