C++ :: Dollar To Coin Value Program?
Jan 26, 2014
I am currently using Xcode on a Mac to compile a c++ program. My class uses Codeblocks and I am having issues with the variable names and commands.
The assignment is to write a program that calculates the quarters, dimes, nickels, and pennies needed to input the amount of money. We have to apply the largest value coins first and use modulus for the remainder.
the input for turning in is: 398
This is idea I am getting...
#include <iostream>
int input;
int quarters, dimes, nickels, pennies;
cout<<"Enter dollar amount: ";
cin>> input;
quarters = inputquarters/.25;
[Code] ....
View 1 Replies
ADVERTISEMENT
Oct 20, 2013
I have a current assignment for C++ involving us to make a program to determine coin change for example if you input the number 127 you would need 2 half dollars 1quarter and 2 pennies I have no way how to program this.
This is my code that doesn't do what i want it to
#include <iostream>
using namespace std;
int main ( ) {
float change;
int half_dollars, quarters, dimes, nickels, pennies; // declare variables
[Code] ....
View 1 Replies
View Related
Nov 14, 2013
Write a program that simulates coin tossing. For each toss of the coin, the program should print Heads or Tails. Let the program toss the coin 100 times and count the number of times each side of the coin appears. Print the results. The program should call a separate function flip that takes no arguments and returns 0 for tails and 1 for heads. [Note: If the program realistically simulates the coin tossing, then each side of the coin should appear approximately half the time.]
View 7 Replies
View Related
Mar 1, 2013
I'm currently working on a program to take the user's input as DDDD.CC and then converting it to the least amount of coins using quarters, dimes, nickels, and pennies. I was told to not use any doubles or floats as they would produce errors. And supposed to the use the library function atoi() after I take the input user's amount as a string to convert it into an integer.
So far the string input has worked and it produced the right number of quarters but it leaves off the cents. For example, I put in 352.23 and it gives the right amount of quarters but leaves off the 23 cents.here's my code:
#include <iostream> // Allows the program to perform input and output
#include <stdlib.h> // Atoi
#include <string>
using namespace std ; // Enables a program to use all the names in any Standard C++ header
int main() // Start of program execution {
string line ;
[code]....
View 6 Replies
View Related
May 18, 2014
I'm quite new to programming and working on an algorithm for the program so we would have to change that into a workable code for our final program.
This is the algorithm teacher gave us for reference (with the functional decomposition):
3.9.3 convertNetPay()
// convertNetPay(in netPay, out netPayString)
char * convertNetPay(float netPay);
void convertNetPay(float netPay, char * netPayString);
Algorithm:
convertNetPay(in netPay, out netPayString)
Declarations: numHuns, numTens, numOnes as integer
OnesTable as array[9] string = {"One", "Two","Three", ...."Nine"}
"One" --> 0
"Two" --> 1
"Three" --> 2
...
[Code] .....
So that goes my entire instruction on the assignment and I will start my code and be probably asking quite a bit of questions!
Here is my code so far:
Spoiler
#include <stdio.h>
#include <stdlib.h>
#include <cstring>
void convertNetPay(float netPay, char *netPayString) {
int numHuns, numTens, numOnes;
[Code] .....
View 9 Replies
View Related
Aug 11, 2014
I'm just starting to learn C++ with Jumping into C++. In Chapter 9, we are asked to create a coining flipping program. My code runs, but I can't figure out why it keeps printing tails. Not very random. My thing was that I can pick heads if the random number generated from rand() is even, and tails if it is odd. But it just keeps printing tails.
Here is my code:
Code:
#include <iostream>
#include <ctime>
#include <cstdlib>
using namespace std;
int rand_num;
[code].....
View 4 Replies
View Related
Feb 10, 2015
I'm having trouble getting the program to calculate the percentage of times it flipped either heads versus tails. I realize what I currently have doesn't work because above I initialized heads and tails by giving them values of 0, but I'm unsure of how to fix it.
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
int main () {
srand(time(0));
[Code] .....
View 2 Replies
View Related
Feb 20, 2013
My coin/money change code works when there can be an exact change each time, i.e. when the 1 cent option is available. However, when the change options are only $10, $5, $1, 25 cents and 10 cents, it does not give me what I want for instance, I wanted to get change for $237.80, I was expecting to get:
23 10's, one 5, two 1's and 8 dimes. However, the code below is giving me 23 10's, one 5, two 1's and 3 quarters (there is no option left for the 5 remaining cents).how to fix it?
Code:
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
void change(double cents, int a[]);
int main() {
double Dollars;
double cents;
[code]...
View 14 Replies
View Related
Aug 31, 2013
I want to make 10 random numbers thus making 10 random flips of a coin. I am getting 10 tails or 10 heads!
Code: #include <iostream>
#include <ctime>
#include <cstdlib>
using namespace std;
int main(int argc, const char * argv[])
{
[Code].....
View 4 Replies
View Related
May 11, 2013
I am having problems at the end of the program with the do-while loop to restart the program and the validation.
#include <iostream>
#include <string>
#include <iomanip>
#include <cstdlib>
#include <time.h>
using namespace std;
[code]....
View 3 Replies
View Related
Mar 10, 2014
so my homework assignment is to make a program of which removes any notes in a program file.
for example, you run my program it will ask for a filename, when entered it opens the file, copies everything in it and removes any double forward slashes (//) and anything after that up to the new line character ( ) and anything between /* and */ including the /* and */.
i created the entire program and it removed the // and anything after that up to the new line character but will not remove anything after the first / when it finds a /*. This includes the */ at the end of the comment.
the section of code that removes the comments is
//this loop removes all notes
for(i=0;i<buf.st_size;i++) {
if((filecontent[i]=='/')&&(filecontent[i+1]=='/'))//removes notes using //
{
for(i=i;filecontent[i]!='
';i++)
filecontent[i]=' ';}
[Code]....
i know that the section that removes the multi line comments would not remove the final */ at the end if it did work, i was planning to fix that later once it removed the comment.
View 6 Replies
View Related
May 15, 2014
I have my program to load info about students from .txt file
Mrkvicka Jozef 2 1.75 2.1 0.4 1 0.49 1.27
Hrasko Jan 0.1 0.38 1 1.2
Mladek Peter 1.6 0.4 2 1.3 1.8
Petrzlen Robert 0.6 0 1.1 1.1 0.6 0.59
Horvath Ivan 1.6 0.8 0.7 1.3 1
My program is ruuning perfectly only problem is that i must transform it to program uses class, class student . Am very beginer in using classes, so far i do very easy programs using classes.
so far i have this
#include "stdafx.h"
#include "student.h"
student::student(vector<STUDENT> studenti) {
vStudent=studenti;
[Code] ....
I try to make it but its too difficult for me. in that student.h and student .cpp is 50 errors..
Here is my code
#include "stdafx.h"
#include <string>
#include <vector>
#include <sstream>
#include <iostream>
#include <fstream>
using namespace std;
[Code] ....
View 13 Replies
View Related
Jul 22, 2014
I want to make a program which can run in another program. My program have structures flowing:
while (1) {
check (keypressed);
{
do something;
}
}
But check(keypressed) function only active in my program, It can't run in another program.
View 7 Replies
View Related
Sep 4, 2013
I've been working on a small SDL program and decided I wanted to throw the program on to a disc so I could show some people what I'm working on. However, when I try to run the executable, the program crashes and under more details it says that the fault lies on SDL2_ttf.dll .
Why does this program work inside of VS2012e and not in windows?
What I did :
Set the program to release, hit f6, and then tried to run the executable from windows.
Additional information :
Compiler : Visual Studio 2012 express
O/S : Windows 7 64bit
SDL lib : 32 bit version
View 8 Replies
View Related
Aug 27, 2013
For instance Code: int counter;
counter =0;
FILE *pfile;
pfile= fopen("g:myprog.txt" "w");
while (counter >100)
{ fprintf (case counter{something})}; how do I do this?
View 11 Replies
View Related
Mar 20, 2013
Cannot divide the real output of the AVERAGE.:
Code:
#include<stdio.h>
#include<conio.h>
struct student
{
char Name[50];
[Code]....
View 7 Replies
View Related
Dec 8, 2013
how to get the output of this program.. I'm not completely lost but I need it in the simplest terms.
Code:
/*Recursive Trace
Written by Ron
April 2006
*/
[Code]....
View 9 Replies
View Related
Feb 1, 2013
is there anyway to have a program where it ask for three numbers and you shows which which number is the largest and which is the smallest, e.g.
Enter 1st number: 30
Enter 2nd number: 10
Enter 3rd number: 30
Largest = 30
Smallest = 10
View 12 Replies
View Related
Oct 16, 2014
I am working on a program to compute the natural log of numbers using several different methods, but I am having a couple of issues. Firstly, when using Borchardt's Algorithm I almost always end up with nan as a result, even though I am pretty sure I got the formula correct. Also, in my lnDemo.c file It doesnt give me the correct answer and the second time around I get a segmentation fault.
Code:
//myLog.h-------------------------------------------------------
//These functions will compute or aproximate the natural log of a number
//This method will use a formula to compute it
int lnFormula(double x, int m,double *result);
[code]....
View 7 Replies
View Related
Feb 26, 2014
I have written the below code,
#include "stdio.h"
int main() {
int c;
while((c=getchar()) != EOF) {
putchar(c);
}
}
The above program is not terminated.how to terminate it?
View 3 Replies
View Related
Mar 5, 2014
Is it possible to add more than one database in a C# program if so, how?
View 7 Replies
View Related
Mar 6, 2015
I'va create a c program that scans the web from a root it works on mypc but dont works on another pc of my friend.I have created this project with Visual Studio 2013 disabling extension to obtain standard ansi c project.
View 2 Replies
View Related
Jul 2, 2013
I have an issue with a switch case in my program. I execute it and it does fine all the way up to where it says, "Answer (1, 2, or 3): ". When I enter 1, 2, or 3, it gives me' "Not an input choice!" from the default of the switch case.
NOTE: I use Code::Blocks on Windows XP.
Here is the code:
Code:
#include <stdio.h>
#include <string.h>
int main() {
[Code].....
View 8 Replies
View Related
Mar 20, 2014
Can we use more than one 'if' subroutine in one program. I am trying to implement this but if I run the two subroutines at the same time the lower subroutine directly shows "invalid grade". But if I run one at a time then they work perfectly fine.
Why is this happening? Does the compiler think that its the same "if" routine. If so how do I segregate it???
Code:
printf("Enter a score:");
scanf("%d",&gr);
if(gr>=80 && gr<=100)
printf("A Grade
");
if (gr>=60 && gr<80)
printf("B Grade
[Code] ....
View 8 Replies
View Related
Mar 9, 2013
I expected this program to print out:
Code: Enter your desired monthly salary: $2000___
Gee! $2000.00 a month is $24000.00 a year. Instead, it printed out:
Code: Enter your desired monthly salary: $2000___
Gee! $2000.00 a month is $24000.00 a year. I don't understand how it got the extra nextline in the middle.
Here is the code:
Code:
#include <stdio.h>
int main(void) {
float salary;
printf("aEnter your desired monthly salary:");
[Code].....
View 2 Replies
View Related
Oct 7, 2013
I'm trying to successfully run a program that calculates your BMI but, although it runs, it is not giving the the correct math. Instead, it gives me the number i've submitted as my weight as an answer. I'm using Visual Studio 2008 and the formula: weight / (height/100)*2
Here is my code
#include <iostream>
#include <cmath>
using namespace std;
int main() {
int weight;
int height;
double BMI;
[Code] ....
View 2 Replies
View Related