Error Trying to Compile

I am brand new to programming,so I apologize in advance.

I was given an assignment to put together a simple program using putty. I was able to do the first part of the assignment below and everything worked fine.

#include <iostream>
using namespace std;

const float TAX_RATE = 0.06; // sale tax rate
float book1Price = 70.00;
float book2Price = 50.00;
float tax, total;

int main()
{

cout << "**SVSU Bookstore**" << endl;

cout << "Please enter book price 1" << endl;
cin >> book1Price;

cout << endl;
cout << "Please enter book price 2" << endl;
cin >> book2Price;

tax = (book1Price + book2Price) * TAX_RATE;
total = book1Price + book2Price + tax;

cout.setf(ios::fixed);
cout.precision(2);

cout << endl;
cout << "Total: $" << total << endl;
cout << endl;
cout << "Thank you! Have a nice day!!" << endl;

return 0;
}

I now need to edit the above program with the program below that was supplied by the instructor so that it reads from the input file.

#include <fstream>
using namespace std;

float book1Price, book2Price;

int main()
{

ifstream inFile; // Input file
inFile.open("input3.dat"); // Open the input file
inFile >> book1Price >> book2Price; // Read 2 data elements from file, delimited by white space

return 0;
}

This is what I have after I combine them.

#include <fstream>
using namespace std;

const float TAX_RATE = 0.06; // sale tax rate
float book1Price, book2Price;
float tax, total;

int main()
{

cout << "**SVSU Bookstore**" << endl;

ifstream inFile; // Input File
inFile.open("input3.dat"); // Open the Input
inFile >> book1Price >> book2Price; // Read 2 data elements from file, delimited by white space

cout << endl;
tax = (book1Price + book2Price) * TAX_RATE;
total = book1Price + book2Price + tax;

cout.setf(ios::fixed);
cout.precision(2);

cout << endl;
cout << "Total: $" << total << endl;
cout << endl;
cout << "Thank you! Have a nice day!!" << endl;

return 0;
}

When I try to compile in putty it gives me the following errors
- In function 'int main()':
'cout' was not declared in this scope

I have tried searching and "googling" to no avail, so I appreciate any help.


Adam
Last edited on
Well I would have went elsewhere if I knew I would have just gotten a smart-ass answer. I found that, but that does not explain why I get the error I do, nor does it FIX the error. So thanks for nothing.

I guess the sticky about people being courteous on here is inaccurate. I apologize for making you waste your time to make that absurd URL.
I found that, but that does not explain why I get the error I do


OF COURSE it explains. It reads verbatim:

You can get the error
‘cout’ was not declared in this scope
if you forget to include iostream or to use the std namespace.


That surely sounds like an explanation to me. :-) Whether it fits YOUR bill... well, I guess you need to at least read it first to determine that.

So thanks for nothing.

On the contrary: Thank YOU. You made me laugh out loud trying to figure out your definition of "to Google". :-)
Last edited on
Well I'm glad I could make you giggle over Google.

I figured it out. I guess I was NOT UNDERSTANDING that I need the iostream and fstream in order for it to work properly, but I'm sure you knew that simply by looking at what I initially posted. I was looking for an explanation of why what I had wrong and why I needed one thing versus the other.
I did understand that. You just took the whole "let me Google that for you" too seriously. Have you ever said something stupid? I have many times, and people have mocked me about it for months! Just take it as it is: A simple joke. :-) Say "Ok, it was stupid of me not reading carefully and not experimenting a bit before boldly stating that I googled it already.", and just move on. I agree that saying or doing something stupid doesn't make you stupid. Just avoid repetitions. :D
I know it's a joke, and I can understand the humor in it, completely, especially if I was experienced and knew what I was doing. I did experiment to no avail and searched but could not find something that I actually understood. After a couple of hours (no joke) of tinkering with no idea of what outcome I would get, I resorted to coming here against my better judgement because I know how "newbies" get treated by those who know what they are doing. Up until now I wasn't finding humor in anything. But like you said, it is what it is...life goes on. :)
Topic archived. No new replies allowed.