firstly here is the code i'm working on in visual studio

#include "stdafx.h"
#include <iostream>
#include <string>

using namespace std;

struct Car
string r_number,make_of_car,model_of_car;
int mileage;
int age_of_car;

void main ()
int i,num;
Car *car1;

cout << "Please enter the number of cars: ";
cin >> num;

car1= new Car[num];
cout <<"Could not allocate memory!";

for (i=0; i<num; i++)
cout << "\nCar " << (i+1) <<" Registration number: ";
cin >> car1[i].r_number;

cout << "Car " <<( i+1) <<" Make : ";
cin >> car1[i].make_of_car;

cout << "Car " << (i+1) <<" Model: ";
cin >> car1[i].model_of_car;

cout << "Car " <<( i+1) <<" Total mileage: ";
cin >> car1[i].mileage;
if (car1[i].mileage < 0)
// error if age of car is neagitive
printf("Fatal Error: A car cannot have negative mileage.\n\n");

cout << "Car " <<( i+1) <<" age: ";
cin >> car1[i].age_of_car;
if (car1[i].age_of_car < 0)
// error if age of car is neagitive
printf("Fatal Error: A car cannot have negative age number.\n\n");

int opt=0;
cout << "**** CAR EVALUATION SYSTEM ****\n";
cout << "1. Search For a Car\n";
cout << "2. Generate Performence Report\n";
cout << "3. Exit\n";
cout << "Please choose an option:";
cin >> opt;
case 1: 
system ("cls");
cout << "Please enter car's registration number: ";break;

case 2: 
system ("cls");
cout<<"Car registration\tAnnual average mileage\tMileage type";break;

case 3: 
exit (0);

}while(opt != 3);


basicaly where it says case 1 the program needs to clear the screen and ask the user to enter the car’s registration number that s/he wishes to retrieve from the system( which i've done.but how to do this bit,i tried doing it few times but failed:(..here it goes)----- If the car’s detail is found in the system, the program should display the car’s name, make, model, current total mileage, and age. Otherwise, the program should display an appropriate error message to inform the user that the registration number was not found in the system. When this task is finished, the program should return to the main menu.
any help wud be greatly appriciated..thanx in advance

Edited by WaltP: Added CODE Tags

6 Years
Discussion Span
Last Post by pinsickle

do something like

int j = 0
while (j < num && strcmp(enteredNum, car1[j].r_number) !=0)

if (j < num)
  cout << car1[j].milage << car1.[j].(whatever other data);
  cout << "car not found\n"

of course that is a lot to cram in a switch statement so you may want to make the above into a function
also the enteredNum i am referencing is what ever variable the number the user enters to search. I would suggest accepting their data as a string, that way you can use strcmp


wait i'm thinking dumb i thought you had the r_number as a string.
change the strcmp(.....) part to

while (j < num && enteredNum != car1[j].r_number)
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.