View Single Post
  #1 (permalink)  
Old December 25th, 2006, 07:00 PM
bLo bLo is offline
Registered User
 
Join Date: Dec 2006
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default Mysterious Coding

Dear All,

Whatz wrong with this code :

//Compile using minGW 2.05
//project x-1
// coding myterious
//patch no
//boolean true|false ???

#include <iostream>

using namespace std;

void sample_void_1() // learn using void
{

    string name;
    char op = 'y';

    do
    {

    cout << " Please type ur name : ";
    getline(cin, name);

    cout << " Hallo " << name << endl;

    cout << " Again ( Y / N )";
    cin >> op;


    }
    while((op=='y')||(op=='Y'));
}

int main()
{
 sample_void_1();

 return 0;
 }



Result:

 Please type ur name : rere
 Hallo rere
 Again ( Y / N )y
 Please type ur name : Hallo
 Again ( Y / N )y
 Please type ur name : Hallo
 Again ( Y / N )n


Terminated with return code 0
Press any key to continue ...



If im using like this no problem :


#include <iostream>

using namespace std;

int main()
{

    float a,b,result;
    char op; // operator y or n

    do {
    cout << "First number: ";
    cin >> a;

    cout << "Second number: ";
    cin >> b;

    result = a * b ;

    cout << "" << result << endl;

    cout << " Again ( Y / N )";
    cin >> op;

        }
        while((op=='y')||(op=='Y'));


    return 0;
}

Result:

First number: 6
Second number: 7
42
 Again ( Y / N )y
First number: 5
Second number: 5
25
 Again ( Y / N )n


Terminated with return code 0
Press any key to continue ...

Reply With Quote