C and C++

Moderators: None (Apply to moderate this forum)
Number of threads: 28629
Number of posts: 94611

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
c++ errors in program Posted by CherieDrees on 30 Sept 2005 at 3:53 AM
I keep getting the below errors in this training c++ program that converts dollars to 'DWORKS' from the minimum to the maximum dollars entered. Any ideas?
errors:
error C2593: 'operator <<' is ambiguous
error C2593: 'operator <<' is ambiguous
error C3861: 'setiosflags': identifier not found, even with argument-: error C3861: 'setprecision': identifier not found, even with argument-dependent lookup
error C3861: 'setw': identifier not found, even with argument-dependent lookup
error C3861: 'setw': identifier not found, even with argument-dependent lookup


//This program converts Dollars to DWORKS.

#include <iostream>
#include <iomanip>
#include <stdafx.h>


using namespace std;

int main()
{

double mindollars,counter;
double maxdollars;
const double step=.025;
const float dworksToDollar=27.00;

cout << setiosflags(ios::fixed) << setprecision(2);
cout<<"Enter mindollars to convert to DWORKS:\n";
cin>>mindollars;
cout<<"Enter maxdollars to convert to DWORKS:\n";
cin>>maxdollars;
cout << " Exchange Rates\n"; //You are to display the exchange rate (27 to 1) at the top of the table
cout << " Dollars DWORKS\n";
cout << " ------- ------\n";

for (counter=mindollars;counter<maxdollars; counter=counter+step)
cout << setw(9) << mindollars << " " << setw(10) << (counter*dworksToDollar) << " \n";

system("pause");


return 0;
}



Report
Re: c++ errors in program Posted by stober on 30 Sept 2005 at 6:44 AM
:
: << (counter*dworksToDollar) << ;
:

and just what is that supposed to do? That is a typecast but typcasting what? Its very similar to this INCORRECT line

<< (int *) <<

Report
Re: c++ errors in program Posted by CherieDrees on 30 Sept 2005 at 8:01 AM
: :
: : << (counter*dworksToDollar) << ;
: :
:
: and just what is that supposed to do? That is a typecast but typcasting what? Its very similar to this INCORRECT line
:
: << (int *) <<
:
:

Report
Re: c++ errors in program Posted by CherieDrees on 30 Sept 2005 at 8:04 AM
I want to display a table of dollar conversion for each .25 from the min to the max dollars entered.

example:

dollars min $1
dollars max $2

dollars DWORKS
1.00 2.00
1.25 2.50
1.50 3.00
1.75 3.50
2.00 4.00
Report
Re: c++ errors in program Posted by stober on 30 Sept 2005 at 8:37 AM
Oops! my apologizes. I misread that line of the program. Its not a typecast as I said -- it is multiplying two numbers. Your program compiles ok with my compiler VC++ 6.0. The output isn't correct because it is displaying the wrong variable. See below

cout << setw(9) << counter << " " << setw(10) << (counter*dworksToDollar) << " \n"; 

Report
Re: c++ errors in program Posted by CherieDrees on 30 Sept 2005 at 9:40 AM
I credit myself as a slow learner. I've made the change that you mentioned and I still cannot compile in MS Visual Studio.NET 2003.

error C3861 and C2593 on: cout << setiosflags(ios::fixed) << setprecision(2);

I also get errors on all lines with setiosflags, setprecision and setw. Identifier not found.

I appreciate your help!
Report
Re: c++ errors in program Posted by Donotalo on 30 Sept 2005 at 10:40 AM
: I credit myself as a slow learner. I've made the change that you mentioned and I still cannot compile in MS Visual Studio.NET 2003.
:
: error C3861 and C2593 on: cout << setiosflags(ios::fixed) << setprecision(2);
:
: I also get errors on all lines with setiosflags, setprecision and setw. Identifier not found.
:
: I appreciate your help!

i've compiled and run the following code (slightly modified as mentioned stober and according to ur problem) and found no problem:
#include <iostream>
#include <iomanip>
using namespace std;

int main()
{

	double maxdollars, mindollars,counter;
	const double step=.25;
	const float dworksToDollar=27.00;

	cout << setiosflags(ios::fixed) << setprecision(2);
	cout<<"Enter mindollars to convert to DWORKS:\n";
	cin>>mindollars;
	cout<<"Enter maxdollars to convert to DWORKS:\n";
	cin>>maxdollars;
	cout << " Exchange Rates\n"; c
        cout << " Dollars DWORKS\n";
	cout << " ------- ------\n";

	for (counter=mindollars;counter<maxdollars; counter=counter+step)
		cout << setw(9) << counter << " " << setw(10) << (counter*dworksToDollar) << " \n";

	return 0; 
}

Report
Re: c++ errors in program Posted by CherieDrees on 30 Sept 2005 at 11:10 AM
Thank you both for your help! It now will compile in VS.NET 2003. You've made my weekend!
Report
Re: c++ errors in program Posted by stober on 30 Sept 2005 at 10:54 AM
This message was edited by stober at 2005-9-30 10:55:47

I just copy-past your original program into a .NET 2003 C++ win32 console app and it compiled ok. The only change I made was remove the line shown below because stdafx.h should be surrounded by quotes not angle brackets and must be the first include file listed in the program.
#include <stdafx.h>






 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.