Question about a Lambda error??

This is a final project for a class that is supposed to convert dollars to coins. I want it to loop through and show how many quarters, dimes, nickels, and pennies are in the user defined amount. This was pretty much a self guided class, so I am not doing so well, but we are supposed to use an if...else, or do...while, use strings, have multiple outputs to screen, at least one input, use decimals, and if <1, program should break. In my mind this should work, but it isn't working like that in the Visual Studio Express 2013. Any ideas or suggestions would be greatly appreciated!!

{
int value = []; //it is looking for a { for a lambda body right here
double mathResult1 = (value / 0.25);
double mathResult2 = (value / 0.10);
double mathResult3 = (value / 0.05);
double mathResult4 = (value / 0.01);

char string1[] = "quarters";
char string2[] = "dimes";
char string3[] = "nickels";
char string4[] = "pennies";


cout << "enter dollar amount\n";//prompts user for value
cin >> value;//user enters dollar amount

do
{
cout << "You have" << (value / 0.25) << string1;
cout << "You have" << (value / 0.10) << string2;
cout << "You have" << (value / 0.05) << string3;
cout << "You have" << (value / 0.01) << string4;
} while (value >= 1.00);

if (value < 1.00);
else
cout << "Sorry, you are broke\n";

}
What is the int value = []; supposed to do?

What are the mathResults?

The value does not change in the do..while loop, and therefore it executes either once or infinitely.


Please, use the code tags.
The int value = [] is supposed to be any value that a user would enter. I was trying to set up the basic calculation to divide the user entered amount by the actual value of each coin.

Someone else had suggested mathResult, so I honestly don't know. I am trying anything and everything at this point to get this compiled so I can turn it in by tomorrow.
Read "Declaration of variables" from http://www.cplusplus.com/doc/tutorial/variables/
Do you have any tips on getting rid of the "looking for a lambda body" error? I have tried placing {} around just about everything, but that error won't go away.
Just declare an integer variable.

int value;
Thanks that got rid of that last one. I had that before, and thought that I needed to leave some space for the user to enter a value which is why I add brackets to initialize. So now I am getting an uninitialized error for the "value". If I want the value to be initialized by user input, how do I do that?
You'll assign the value the user enters to the variable you've declared. You could initialize it with a default value to replace the uninitialized garbage it holds, that could be done like int value = 0; (The page that keskiverto linked above also addresses initialization of variables.)

But - you don't want to do any calculations (e.g. double mathResult1 = (value / 0.25);) with the variable until after the user enters the number that value will hold.
Ok I am making progress! I think. So now the code will compile and run, but I need spaces between the "You have12quarters" etc, and if I add them into the code lines, nothing happens. The only other issue I am having now is that the statement for the else condition prints along with number of coins.

#include "stdafx.h"
#include <iostream>
using std::cout;
using std::cin;

#include <string>
using std::string;
using std::getline;


int _tmain(int argc, _TCHAR* argv[])
{
int value;//amount to be declared by user

char string1[] = "quarters\n";
char string2[] = "dimes\n";
char string3[] = "nickels\n";
char string4[] = "pennies\n";

cout << "Enter dollar amount\n";//prompts user for value
cin >> value;//user enters dollar amount

double operator1 = (value / 0.25);//calculates number of quarters based on user input
double operator2 = (value / 0.10);//calculates number of dimes based on user input
double operator3 = (value / 0.05);//calucates number of nickels based on user input
double operator4 = (value / 0.01);//calculates number of pennies based on user input

if (value >= 1.00)
{
cout << "You have" << (value / 0.25) << string1;
cout << "You have" << (value / 0.10) << string2;
cout << "You have" << (value / 0.05) << string3;
cout << "You have" << (value / 0.01) << string4;
} else
if (value < 1.00);
cout << "Sorry, you are broke\n";
return 0;
}
Build in the spaces in the text.

e.g. - add a space after have, and before quarters
cout << "You have " << (value / 0.25) << string1; char string1[] = " quarters\n";

Remove the semicolon at the end of the if condition.
if (value < 1.00);

Did you mean to use the operator variables instead of recalculating value/.25 etc. again in the output?

Is this actually calculating what you need? For example, if someone said they had 1.67 - is the output supposed to say this (which adds up to more than 1.67)

You have 6.68 quarters
You have 16.## dimes
You have 33.## nickels
You have 167 pennies

or should it give a breakdown like this to add up to 1.67
You have 6 quarters
You have 1 dimes
You have 1 nickel
You have 2 pennies


Last edited on
The directions for the assignment said whole numbers, so I am guessing that he won't even try something like 1.67. Thank you so much for all of your help!! It might just get me to pass this class!
Topic archived. No new replies allowed.