I used printf and scanf in c++ codeblocks now trying to change Variables to cout and cin lots of issues with my change machine

Errors
error: no match for operator>> in std::cin >> "%d"

#include <iostream>

using namespace std;

int main(void)
{
int change;
int coins;
int remainder;

cout << "please enter an amount of change: ";
cin >> "%d", &change;

cin >> change>=25;
{
coins = change/25;
cout >> "Quarters: %d\n", coins;
remainder = change%25;
}

cin >> change>=10;
{
coins = remainder/10;
cout >> "Dimes: %d\n", coins;
remainder = remainder%10;
}

cin >> remainder>=5;
{
coins = remainder/5;
cout >> "Nickles: %d\n", coins;
remainder = remainder%5;
}

cin >> remainder>0;
{
cout >> "Pennies: %d/n", remainder;
}
std::cin >> change; std::cin knows how to read it in.
You also can just do std::cout << "Quarters: " << coins << std::endl;

std::cin knows how to read in some types by default, and all integral types and double, float are included.
std::cout also knows how to print those types.

I'm not sure what you meant to do with cin >> change>=10; but I'm guessing you meant to test if (change >= 10).
closed account (E0p9LyTq)
Don't use C library printf() and scanf() format specifiers with std::cout and std::cin.

cin >> "%d", &change; should be cin >> change;

cout >> "Dimes: %d\n", coins; should be cout << "Dimes: " << coins << "\n";
Last edited on
#include <iostream>

using namespace std;

int main()
{
int change;
int coins;
int remainder;

std::cout << "please enter an amount of change \n";
cin >> change;

if (change >= 25)
{
coins = change/25;
cout << "Quarters: " << coins << "\n";
remainder = change%25;
}

if (change >= 10)
{
coins = remainder/10;
cout << "Dimes: " << coins << "\n";
remainder = remainder%10;
}

if (change >= 5)
{
coins = remainder/5;
cout << "Nickles: " << coins << "\n";
remainder = remainder%5;
}

if (change >= 0)
{
cout << "Pennies: " << coins << "\n";
}
is this better?
Yes, your cin and couts are better.

You have a problem with change and remainder though.

Line 18: You calculate the remainder, but then at line 20, you test change >= 10. You should either test remainder, or decrement change by the value of the coins issued.

Same for nickels and pennies.

PLEASE USE CODE TAGS (the <> formatting button) when posting code.
It makes it easier to read your code and also easier to respond to your post.
http://www.cplusplus.com/articles/jEywvCM9/
Hint: You can edit your post, highlight your code and press the <> formatting button.

Im getting an error at the end of the code for } for error expected '}' at the end of input


#include <iostream>

using namespace std;

int main()
{
int change;
int coins;
int remainder;

std::cout << "please enter an amount of change \n";
cin >> change;

if (remainder >= 25)
{
coins = change/25;
cout << "Quarters: " << coins << "\n";
remainder = change%25;
}

if (remainder >= 10)
{
coins = remainder/10;
cout << "Dimes: " << coins << "\n";
remainder = remainder%10;
}

if (remainder >= 5)
{
coins = remainder/5;
cout << "Nickles: " << coins << "\n";
remainder = remainder%5;
}

if (remainder >= 0)
{
cout << "Pennies: " << coins << "\n";
}
That's because you're missing a } at the end of your code.

If you used code tags and indented your code you would have noticed that the last line was indented incorrectly, and would have been able to fix your braces.

Also, if you read the error message, you probably could have discerned that the compiler couldn't find a } at the end of the file.
Last edited on
You have been asked multiple times to use code tags. PLEASE DO SO.
http://www.cplusplus.com/articles/jEywvCM9/
Hint: You can edit your post, highlight your code and press the <> formatting button.

If you're not going to make the slightest bit of effort to make your posts readable, why should we spend the slightest bit of effort helping you?
I will not respond further until you apply code tags.
Topic archived. No new replies allowed.