Help with Program

Can anyone help me with what is wrong with the program? I cant get it to compile.

/* Dollar to Coin Conversion.c
Final Project */
#include <iostream>
using namespace std;

/* function main begins program execution */
int main( void )
{
const int pennies_per_dollar=100;
const int nickles_per_dollar=20;
const int dimes_per_dollar=10;
const int quarters_per_dollar=4;

int values={25,10,5,1},
int description={"quarter", "dime", "nickle", "penny"};
}
//declare variables
int dollarAmount;
newTotal;
selection;

cout<<"Please enter a dollar amount";//user asked for dollar value
cin>>dollarAmount;//user enters dollar amount
cout<<"Choose the coin denomination";//user asked to choose coin
cout<<"Pennies, Nickles, Dimes, Quarters";//user given options of coins

if (int dollarAmount<=1)
return -1;
else if (selection==pennies);{newTotal=dollarAmount*100}
else if (selection==nickles);{newTotal=dollarAmount*20}
else if (selection==dimes);{newTotal=dollarAmount*10}
else if (selection==quarters);{newTotal=dollarAmount*4;}
cout<<newTotal;
{
1
2
3
4
else if (selection==pennies);{newTotal=dollarAmount*100}
else if (selection==nickles);{newTotal=dollarAmount*20}
else if (selection==dimes);{newTotal=dollarAmount*10}
else if (selection==quarters);{newTotal=dollarAmount*4;}


This is a mess.

Here is how to use an if statement.

1
2
3
4
if (condition) // NO SEMICOLON
{ /* some code*/ ; /* YES SEMICOLON */}
else if (condition) // NO SEMICOLON
{ /* some code*/ ; /* YES SEMICOLON */}
Last edited on
1
2
3
4
5
6
7
8
9
10
int main( void )
{
const int pennies_per_dollar=100;
const int nickles_per_dollar=20;
const int dimes_per_dollar=10;
const int quarters_per_dollar=4;

int values={25,10,5,1},
int description={"quarter", "dime", "nickle", "penny"};
}

Above is your main() function.
The rest is code which is not part of any function. It should be inside main, or inside some other function.
It ends with a trailing opening brace, which makes it look as though this is incomplete.
Last edited on
Also
1
2
int values={25,10,5,1},
int description={"quarter", "dime", "nickle", "penny"};


should be
1
2
int values[]={25,10,5,1};
char description[]={"quarter", "dime", "nickle", "penny"};


I cleaned it up a little, but still confused....


/* Dollar to Coin Conversion.c
Final Project */
#include <iostream>
using namespace std;

/* function main begins program execution */
int main( void )
{
const int pennies=1;
const int nickles=5;
const int dimes=10;
const int quarters=25;
int newTotal=0;//amount of money *100/coin

int values[]={25,10,5,1};
char description[]={"quarter", "dime", "nickle", "penny"};

//declare variables
int dollarAmount;
newTotal;
selection;

cout<<"Please enter a dollar amount";//user asked for dollar value
cin>>dollarAmount;//user enters dollar amount
cout<<"Choose the coin denomination";//user asked to choose coin
cout<<"Pennies, Nickles, Dimes, Quarters";//user given options of coins

if ( dollarAmount<=1)//if dollar amount is less or equal to one
return -1;
else if (selection==pennies)//if user selects pennies
return (newTotal=(dollarAmount*100)/pennies);
else if (selection==nickles)//if user selects nickles
return (newTotal=(dollarAmount*100)/nickles);
else if (selection==dimes)//if user selects dimes
return (newTotal=(dollarAmount*100)/dimes);
else if (selection==quarters)//if user selects quarters
return (newTotal=dollarAmount*100)/quarters);
cout<<newTotal;
return 0;
}
char description[]={"quarter", "dime", "nickle", "penny"};


That will not work cause a char is only one or two characters and initialized with '...' not "...". Making it char* should help.--but not the best!

newTotal;
selection;


After: int dollarAmount;?? no variable type. if you wanted 'em all to be int then separate them with a comma:

int dollarAmount,newTotal,selection;

else if (selection==quarters)//if user selects quarters

forgot the trailing ';' right?

TIP**Try reading compile errors and warnings. Understanding them helps a lot. If you still don't gem 'em, then post!**

Also, remember to use code tags next time ur posting a code, this makes it a lot easier to help.

Thanks,
Aceix.
Last edited on
Opps sorry for the typo in char description[]={"quarter", "dime", "nickle", "penny"};

it needs to read char *description[]={"quarter", "dime", "nickle", "penny"};
Topic archived. No new replies allowed.