Can anyone tell me why I get an error on my last cout?
#include <iostream>
#include <cmath>
#include <stdio.h>
#include <cstring>
#include <conio.h>
using namespace std;
inline void keep_window_open() { char ch; cin>>ch; }
int main()
{
cout << "How many pennies do you have?\n";
int pennies;
cin >> pennies;
double total_pen;
total_pen = (0.01 * pennies);
if (pennies >= 1)
{
string penn = " pennies.";
}else
{
string penn = " penny.";
} cout << "How many nickles do you have?\n";
int nickles;
cin >> nickles;
double total_nic;
total_nic = (0.05 * nickles);
if (nickles >= 1)
{
string five = " nickels.";
}else
{
string five = " nickel.";
} cout << "How many dimes do you have?\n";
int dimes;
cin >> dimes;
double total_dim;
total_dim = (0.10 * dimes);
if (dimes >= 1)
{
string ten = " dimes.";
}else
{
string ten = " dime.";
} cout << "How many quarters do you have?\n";
int quarters;
cin >> quarters;
double total_qua;
total_qua = (0.25 * quarters);
if (quarters >= 1)
{
string twentyfive = " quarters.";
}else
{
string twentyfive = " quarter.";
} cout << "How many half-dollars do you have?\n";
int half_dollars;
cin >> half_dollars;
double total_dol;
total_dol = (0.50 * half_dollars);
if (half_dollars >= 1)
{
string fifty = " half dollars.";
}else
{
string fifty = " half dollar.";
}
string saying = "You have ";
cout << saying pennies penn << "\n" << saying nickles five << "\n" << saying dimes ten << "\n" << saying quarters twentyfive << "\n" << saying half_dollars fifty << "\n";
keep_window_open()
return 0;
}
Add more <<:
cout << saying << pennies << penn << "\n"
<< saying << nickles << five << "\n"
<< saying << dimes << ten << "\n"
<< saying << quarters << twentyfive << "\n"
<< saying << half_dollars << fifty << "\n";
EDIT: Also, you are declaring variables in inner blocks - their names are no longer valid outside. Declare your strings earlier.
You are missing the << between the variables.
Try:
cout << saying << pennies << penn << "\n" << saying << nickles << five << "\n" << saying << dimes << ten << "\n" << saying << quarters << twentyfive << "\n" << saying << half_dollars << fifty << "\n";
Update:
The scope of some of your variables, such as penn, means they cannot be seen in the cout statement.
You need to declare the variables outside the if/else statements.
Also, as mentioned by @Color Bend, you are missing a semicolon after the keep_window_open() function.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With