C++ requires a type specifier for all declarations & Expected unqualified-id (Debugging help needed)

93 views Asked by At

Edited*

I made a few changes to the code and resolved the major issues. A few of the lines still have these errors, so I think a brief idea of what normally fixes these kinds of errors and what they actually mean should be about all that's left. Thank you guys!

    #include <iostream>
    #include "RetailItem.h"
    using namespace std;

    int main()
{
    RetailItem *item1 = nullptr;
    RetailItem * item2 = nullptr;
    RetailItem * item3 = nullptr;

    //objects
    item1 = new RetailItem; // c++ requires a type specifier for all declarations
    item2 = new RetailItem; // c++ requires a type specifier for all declarations
    item3 = new RetailItem; // c++ requires a type specifier for all declarations

    //first item
    std::cout << "Please enter the price for the first item." << endl; //expected unqualified-id
    std::cout << "Price must be greater than 0: " << endl; //expected unqualified-id

    cin >> retailPrice; //expected unqualified-id
    while (retailPrice < 0) //loop //expected unqualified-id
    {
        cout << "Price must be greater than 0." << endl;
        cout << "Please try again: " << endl;
        cin >> retailPrice;
    }
    item1 = setPrice(retailPrice); // c++ requires a type specifier for all declarations
    cout << "Please enter number of items in inventory for item 1: " //expected unqualified-id
    cin >> retailUnitsOnHand;
    while(retailUnitsOnHand < 0) //expected unqualified-id
    {
    cout << "Inventory must be greater than 0." << endl;
    cout << "Please enter number of items in inventory for item 1: "
    cin >> retailUnitsOnHand;
    }
    item1 = setUnitsOnHand; // c++ requires a type specifier for all declarations
}
1

There are 1 answers

1
AudioBubble On

Your code needs to be in a function.

i.e.

int main() {