Basic C++ Program

Computer Science | Artificial Intelligence | Computational Biology | Chess | Blender

Basic C++ Program

This is a simple console-based program that yee prints information that shows you a car in stock. The program is a basic introduction to C++ programming and is used to demonstrate the syntax and structure of a C++ program.

Basic C++ Code

#include <iostream>

int main() {
    std::string car = "Toyota";
    std::string model = "Corolla";
    int year = 2020;
    double price = 20000.00;

    bool buyer = false;
    std::string carChoice = " ";

    while (buyer == false) {
        std::cout << "Which car do you like? ";
        std::getline(std::cin, carChoice);
        if (carChoice == car) {
            std::cout << "You bought a " << car << " " << model;
            std::cout << " for $" << price << std::endl;
            buyer = true;
        }
        else {
            std::cout << "Sorry, we don't have << carChoice << "." << std::endl;
        }
        buyer = true;
    }

    return 0;
}