Click here to Skip to main content
15,897,187 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C++
#include <iostream>
#include <Windows.h>
using namespace std;

class Owned {
    public:
    string value;
    string brand;
    string model;
    int ID;
    int year;
    int price;
    string fuel;
    string choice;
    int Balance = 100000;
    string fullname = brand + model;


};

class Cars {
    public:
    int price;
    string brand;
    string model;
    int ID;
    int year;
    string fuel;
    string choice;
    string fullname = brand + model;
    void myMethod () { // A method is a function inside a class

    }
};

int main () {

Cars car1;
    car1.ID = 1;
    car1.brand = "Toyota";
    car1.model = "Supra";
    car1.year = 2016;
    car1.price = 75,000;
    car1.fuel = "Petrol";
Cars car2;
    car2.ID = 2;
    car2.brand = "Toyota";
    car2.model = "Land Cruiser";
    car2.year = 2021;
    car2.price = 70,000;
    car2.fuel = "Diesel";

Cars car3;
    car3.ID = 3;
    car3.brand = "Toyota";
    car3.model = "Rav4";
    car3.year = 2018;
    car3.price = 62,000;
    car3.fuel = "Hybrid";

cout << car1.ID << "." << car1.brand << " " << car1.model << " " << car1.year << endl;
cout << "$" << car1.price << endl;
cout << "Fuel Type:" << car1.fuel << endl;
cout << endl;
cout << "_____________________________________________________________";
cout << endl;
cout << car2.ID << "." << car2.brand << " " << car2.model << " " << car2.year << endl;
cout << "$" << car2.price << endl;
cout << "Fuel Type:" << car2.fuel << endl;
cout << endl;
cout << "_____________________________________________________________";
cout << endl;
cout << car3.ID << "." << car3.brand << " " << car3.model << " " << car3.year << endl;
cout << "$" << car3.price << endl;
cout << "Fuel Type:" << car3.fuel << endl;
cout << endl;


 int choice;
 cin >> choice;
 if (choice = 1) {
        string yesno_variable1;
        cout << car1.year << " " << car1.brand << car1.model << endl;
        cout << "Are you Sure?" << endl << "Yes/No";
        cin >> yesno_variable1;
        if (yesno_variable1 == "yes")
        {
            Owned ocar1;
                ocar1.ID = car1.ID;
                ocar1.brand = car1.brand;
                ocar1.model = car1.model;
                ocar1.year = car1.year;
                ocar1.price = car1.price;
                ocar1.fuel = car1.fuel;
                ocar1.fullname = car1.fullname;
        Owned.Balance - car1.price;   
// Console outputs "line 96 & 98error: expected unqualified-id before '.' token"
            if (car1.price>Owned.Balance) {
            Owned.Balance + car1.price;
            cout << "Not Enough Money";}} }

}


What I have tried:

I have tried changing the indentation of the statement to clarify non-relation to the object statement.
Posted
Updated 28-Jul-21 17:38pm
v2

The problem lines are these :
C++
if (car1.price>Owned.Balance) {
    Owned.Balance + car1.price;
The token in question is Owned. It is a class. Where it is used requires an instance of a type and Owned is a type.

The second line is also an improper expression. What is done with the result of the statement? You might want to use the += operator there instead.
 
Share this answer
 
What is this supposed to be ?
C++
Owned.Balance - car1.price;   
...
Owned.Balance + car1.price;

as far as I understand, those lines are not C++.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900