C++ While in OOP

Where i can insert while instruction in my program???

#include<iostream.h>

class AUTOMOBILES
{
private:
float Miles;
float Gallons;
float MPG;
float TotalMPG;

public:
void masukNilai();
void prosesKira();
void paparHasil();
};

void AUTOMOBILES::masukNilai()
{
cout<<"Enter the miles used : ";
cin>>Miles;
cout<<"Enter gallons : ";
cin>>Gallons;
}

void AUTOMOBILES::prosesKira()
{
MPG=(Miles/Gallons);
}

void AUTOMOBILES::paparHasil()
{
cout<<"MPG this tank full : "<<MPG;
cout<<"\nTotal MPG : "<<MPG;
}

void main()
{
AUTOMOBILES Nombor1;
Nombor1.masukNilai();
Nombor1.prosesKira();
Nombor1.paparHasil();
}

Result like this

Enter the miles used : 287
Enter gallons : 13
MPG this tank full : 22.0769
Total MPG : 22.0769
In one of the functions, of course.
I think you are using turbo C++ so at first I want to suggest you to use code::blocks IDE with minGW.Your code is older version of c++ latest version of c++ compiler does support void main() it must be return type.
you can use while loop in main function like this
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
int main()
{
    char check='y';
    while(check=='y')
    {
AUTOMOBILES Nombor1;
Nombor1.masukNilai();
Nombor1.prosesKira();
Nombor1.paparHasil();
cout<<endl<<endl;
cout<<"Do you want to input another data:y/n "<<endl;
cin>>check;
    }
return 0;
}

Don't forgot to change your header include form #include<iostream.h> to#include<iostream>
and also add
using namespace std; below header include
Topic archived. No new replies allowed.