Question:

Basic c++ programming help?

by  |  earlier

0 LIKES UnLike

I am trying to get this program to execute and it keeps giving me error and my debugger is not working help please :0)

C:\Program Files\Microsoft Visual Studio\MyProjects(12): error C2065: 'tickets' : undeclared identifier

C:\Program Files\Microsoft Visual Studio\MyProjects\(13) : error C2065: 'cost' : undeclared identifier

C:\Program Files\Microsoft Visual Studio\MyProjects(13) : error C2296: '*' : illegal, left operand has type 'int [6]'

C:\Program Files\Microsoft Visual Studio\MyProjects\(19) : error C2679: binary '>>' : no operator defined which takes a right-hand operand of type 'int [6]' (or there is no acceptable conversion)

Error executing cl.exe.

4 error(s), 0 warning(s)

# include <iostream>

# include <iomanip>

using namespace std;

int main()

{

cout << setprecision(2)

<<setiosflags(ios::fixed)

<<setiosflags(ios::showpoint);

double city_price[6] = {56.79, 105.69, 93.49, 155.99, 87.49, 73.99};

tickets = 0<5;

cost = city_price * tickets;

char response;

do

{

cout << endl <<endl <<"What is the number of your desitantion city?";

cin >> city_price;

cout << endl << endl <<"How many tickets do you wish to purchase?";

cin >> tickets;

cout << endl << endl << "The cost is: ";

cin >> cost;

cout << endl << endl;

cout << "City and Price:" << setw(7) << city_price << endl;

cout << "Number of tickets:" << setw(7) << tickets << endl;

cout << "-------------------" << endl;

cout << "Your cost:" << setw(7) << cost << endl;

cout << "Do you wish to purchase more tickets? (Y/N): ";

cin >> response;

}

while (response == 'Y' || response == 'y');

return 0;

}

 Tags:

   Report

4 ANSWERS


  1. i&#039;m guessing a bit here but I think you&#039;re trying to input a city number (which relates to the index of the city_price array) and number of tickets a person wants to buy. Then you want to show the user how much their &#039;order&#039; costs in total? If so you want something like this:

    double city_price[6] = {56.79, 105.69, 93.49, 155.99, 87.49, 73.99};

    int cityNumber = 0;

    int tickets = 0;

    double totalCost = 0;

    char response;

    do

    {

    cout &lt;&lt; endl &lt;&lt;endl &lt;&lt;&quot;What is the number of your desitantion city?&quot;;

    cin &gt;&gt; cityNumber;

    do

    {

    cout &lt;&lt; endl &lt;&lt; endl &lt;&lt;&quot;How many tickets do you wish to purchase?&quot;;

    cin &gt;&gt; tickets;

    }

    while (tickets &lt; 1 || tickets &gt; 5)

    cout &lt;&lt; endl &lt;&lt; endl &lt;&lt; &quot;The cost is: &quot; &lt;&lt; city_price[cityNumber];

    cout &lt;&lt; endl &lt;&lt; endl;

    cout &lt;&lt; &quot;City and Price:&quot; &lt;&lt; setw(7) &lt;&lt; city_price[cityNumber] &lt;&lt; endl;

    cout &lt;&lt; &quot;Number of tickets:&quot; &lt;&lt; setw(7) &lt;&lt; tickets &lt;&lt; endl;

    cout &lt;&lt; &quot;-------------------&quot; &lt;&lt; endl;

    cout &lt;&lt; &quot;Your cost:&quot; &lt;&lt; setw(7) &lt;&lt; city_price[cityNumber] * tickets &lt;&lt; endl;

    cout &lt;&lt; &quot;Do you wish to purchase more tickets? (Y/N): &quot;;

    cin &gt;&gt; response;

    }

    while (response == &#039;Y&#039; || response == &#039;y&#039;);


  2. add &lt;iostream.h&gt; to header files (.h)

    download best ebooks for C-C++ here: http://vicky-e-books.blogspot.com

  3. Its nice to give him the answer, but better to include his mistakes.

    You didn&#039;t declare tickets and cost and then tried to use them.


  4. You haven&#039;t defined what &quot;tickets&quot; is. You have a statement that says:

        tickets = 0&lt;5;

    What does that mean? If tickets is a bool, then it has the value true (since 0 is less than 5). However, I think you mean somethign else, but I can&#039;t even guess at it.

    The other problems is that you&#039;re multiplying 16 numbers with this non-existent tickets - C++only allws you to multiply one number at a time.

Question Stats

Latest activity: earlier.
This question has 4 answers.

BECOME A GUIDE

Share your knowledge and help people by answering questions.