Im trying to learn how to make a program repeat itself and then terminate it with a y/n function ? i know i use a "while ( again == y)" line like that im just not sure were ?
Heres my source file (I think it goes here ?) could someone show me how to accomplish this ?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
#include "vehiclee.h" //include the declaration of the class
#include "Motorbike.h"
#include <iostream>
usingnamespace std;
int main() {
vehicle vehicle ; //object of the class vehicle
cout << "\nThe speed is: " << vehicle.getSpeed(); //shows speed on screen
motorbike motorbike;
cout << "\nThe Number Of Wheels is: " << motorbike.askWheels();
cout << "\nThe Bike Type is: " << motorbike.askBikeType();
cout << "\nThe Radius Of The Petrol Tank is: " << motorbike.askTankRadius();
cout << "\nThe Length Of The Petrol Tank is: " <<motorbike.askTankLength();
cout << "\nThe Tank Volume is: " << motorbike.getTankVolume();
return 0;
}
#include "vehiclee.h" //include the declaration of the class
#include "Motorbike.h"
#include <iostream>
usingnamespace std;
int main() {
char again = 'y';
do {
vehicle vehicle ; //object of the class vehicle
cout << "\nThe speed is: " << vehicle.getSpeed(); //shows speed on screen
motorbike motorbike;
cout << "\nThe Number Of Wheels is: " << motorbike.askWheels();
cout << "\nThe Bike Type is: " << motorbike.askBikeType();
cout << "\nThe Radius Of The Petrol Tank is: " << motorbike.askTankRadius();
cout << "\nThe Length Of The Petrol Tank is: " <<motorbike.askTankLength();
cout << "\nThe Tank Volume is: " << motorbike.getTankVolume();
cout << "\nWould you like to repeat (y or n): ";
cin >> again;
} while (again == 'y');
return 0;
}
Oh ok know i understand thank you :D but lets say i wanted the program to repeat itself automatically then after lets say 3 repeats it asks the user to enter again
#include "vehiclee.h" //include the declaration of the class
#include "Motorbike.h"
#include <iostream>
usingnamespace std;
int main() {
char again = 'y';
do {
staticint iterations = 0;
vehicle vehicle ; //object of the class vehicle
cout << "\nThe speed is: " << vehicle.getSpeed(); //shows speed on screen
motorbike motorbike;
cout << "\nThe Number Of Wheels is: " << motorbike.askWheels();
cout << "\nThe Bike Type is: " << motorbike.askBikeType();
cout << "\nThe Radius Of The Petrol Tank is: " << motorbike.askTankRadius();
cout << "\nThe Length Of The Petrol Tank is: " <<motorbike.askTankLength();
cout << "\nThe Tank Volume is: " << motorbike.getTankVolume();
iterations++;
if (iterations >= 3) {
cout << "\nWould you like to repeat (y or n): ";
cin >> again;
}
} while (again == 'y');
return 0;
}