C :: Using Functions To Convert Change Into Dollars
Jul 20, 2013
I know this is pretty basic script the problem I have is that I have to use functions for each calculation. The problem I face is that when the user types in the amount of quarters, dimes, nickels, and pennies when a function tries to add them together it displays a huge number instead of the right number.
Here is my code:
#include <stdio.h>
void insert_money(int p, int n, int d, int q, int total){
printf("How much of each coin do you want to insert:
");
printf("Quarters: ");
scanf("%d", &q);
[Code] ....
View 7 Replies
ADVERTISEMENT
Sep 21, 2013
For the program, you will write a utility that converts dollars to coins. It is a simple program that must have the following:
-Multiple outputs to the screen
-At least one input
-The use of integers and strings
-Looking or repetition with Do..While, If..Else
-Must have some output text to show correct value of coins that would be converted from the dollars.
-Code must include comments explaining your reason for the code section or what the code is doing
-Code must compile
-Whole dollars only. If value is less than 1 or 0, the program should break or exit.
-Turn in your source code (.cpp file) to your instructor with your filename including your first and last name and your compiled executable.
View 3 Replies
View Related
Jan 17, 2014
the book I learn from gave a task to write a program which gets a matrix , and we have to write a function that switches 2 columns or rows the user inputs .as far as I know a function can not change variables in the main function without using pointers .so , theoretically, can a function described here can be written without using pointers ? as far as I tried - it can not.
View 9 Replies
View Related
Oct 14, 2013
I try the functions pointers too, but without success. I understand the objects are the way for work with class's. until here fine. But why i can't change the virtual functions from an object? is there anyway for do it? Ican't do, outside of classfunctions, these code:
#include <iostream>
using namespace std;
class test {
public:
virtual void created(){};
[Code] ....
How i can validate these line:
void a::created()
???
View 2 Replies
View Related
Mar 29, 2014
current functions are:
char *createEnvironment(int width, int height, int numWoodChips);
void printEvrionment(char *environment, int width, int height);
need to be:
int* createEnvironment(int width, int height, int numWoodChips);
void printEvrionment(int* environment, int width, int height);
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
[Code]....
View 1 Replies
View Related
Nov 20, 2012
Working in Win32 console app (VS 2010) I have been trying to convert several Unicode (UTF-16) C++ functions to Ansi C (UTF-8). The test app includes two tokenizer classes, each of which work perfectly well in their respective environments, CTokA and CTokW (UTF-8 and UTF-16).
A problem arises when I attempt to run the UTF-8 functions when the Character Set properties is set to 'Use Unicode Character Set' in that std::string manipulations do not perform as expected, e.g.,
printf("start
");
gets reproduced as
printf("start
");══════════ ²²²²
Attempting to null terminate the string where it is supposed to end simply results in a space in that position and the garbage end persists, e.g.,
printf("sta t
");══════════ ²²²²
Code:
sline[11] = 0x0000;
If I attempt to change the Character Set property to 'Use Multibyte Character Set' or 'Not Set', the app will not compile and hundreds of errors occur. Of course, I can eliminate all of the UTF-16 code, but it strikes me that it should not be necessary. Perhaps if M$ made everything UTF-16 without all of the necessary decorations like 'L' and '_T(', life would be much simpler. Unfortunately, I have a very extensive UTF-8 app under 10 years of development that works quite well, but my UTF-16 (Unicode) conversion doesnt work as well because of the mixing of pointers (I think), so I have had to revert much of the code back to UTF-8. (All of which has nothing to do with my question but is simply psychotheraputic for me to ventilate on.)
My question is this: Can UTF-8 and UTF-16 code coexist in a single Win32 console app?
View 6 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
Sep 23, 2012
Code:
template<class T>
class Convert {
T data;
public:
Convert(const T& tData = T()) : data(tData)
[Code] ....
Why do we use operator? Is float and double function names below?
Code:
Convert<int>::operator<float> float();
Convert<int>::operator<double> double();
View 1 Replies
View Related
Mar 20, 2014
I'm a little confused by my programming assignment this week. I've been working at it Wednesday and I've made progress but I'm still confused as to how I'm supposed to do this. The class I made is called Stack, and it's derived from a template class called StackADT. We also utilize a class called unorderedLinkedList, which is derived from a class called linkedList.
We're supposed to implement all of the virtual functions from stackADT in the Stack class. The Stack data is stored in a an unorderedLinkedList, so what I'm confused by is how to implement a few of the Stack functions because there are no functions in unorderedLinkedList which we could call to manipulate the data.
As you can see from my attached code, I'm really confused by how I'm supposed to implement the pop() and top() functions, and I also think my initializeList() function is wrong. We don't have any similar functions in unorderedLinkedList to call, so I'm at a loss of how i'd access my unorderedLinkedList. My initial thought was to call the similar functions in the class that unorderedLinkedList was derived from, linkedList, but I'm unsure of this is what we're supposed to do, or if theres actually a way to access my unorderedLinkedList without having to use the functions from the base class.
NOTE: We're not allowed to modify stackADT, unorderedLinkedList, and linkedList.
Stack.h
#include "stackADT.h"
#include "unorderedLinkedList.h"
template<class Type>
class Stack: public stackADT<Type>{
template <class T>
struct nodeType
{
T info;
nodeType<T> *link;
[Code]...
View 3 Replies
View Related
May 3, 2013
At the moment im trying out with pointing to an array of functions. I got this working as following:
typedef void (* functionPtr) ();
functionPtr functions[2][2]={{do11,do12}, {do21,do22}};
void do11(){DEBUG_PRINTLN("11");}
void do12(){DEBUG_PRINTLN("12");}
void do21(){DEBUG_PRINTLN("21");}
void do22(){DEBUG_PRINTLN("22");}
void loop(){
A=0;
B=1;
functions[A][b]();
}
But now I'm trying to use this to point to a function inside a class so instead of do11, i want to be able to point to Basic.Do11. Somehow this doesnt work and I keep on getting this message:
error: argument of type 'void (Basic::)()' does not match 'void (*)()'
View 2 Replies
View Related
Mar 6, 2015
how to use a keyboard. I have the program running now in Dev-C++, but the standard display letters on the monitor are small and sort of boring.Within a C program, is there a way to change the font to something stylish? Enlarge the letters? Change the color from letter to letter?
In the old days, there was graphics.h, but that isn't included now, and I would prefer to use some modern extension. I'd like to write it on Win7, then move it to Linux on Raspberry Pi. It would be nice to avoid a full-scale graphics system like OpenGL.
View 1 Replies
View Related
Nov 14, 2013
I have a .txt file which contains a large amount of ones and zeros (tile map for a game) and basically I just want to know how to change say just the 12th value in the file from a 1 to 0 .....
View 2 Replies
View Related
Sep 3, 2014
I am working on a program that is supposed to do I/O file streaming. I dont know if I can properly explain how its supposed to work but I have found the error on my code, I just dont know WHY the error is happening? If you look in the while loop, count changes values like it should, but MOVE and TIP doesnt. Count starts at value 2. So move is 108. Then count becomes 4, but move stays at 108?
tring rec;
fstream myfile("File.txt", ios::in | ios::out);
myfile.seekg(myfile.tellg(), ios::beg);
myfile.seekp(51, ios::beg);
[Code]....
The lines of code im getting errors on is
int move = count * 54;
int tip = move + 51;
Move wont change its value? It stays 108, causing this infinite while loop. Where is the error in my code to cause move to not change values like count does?
I seem to be struggling with I/O File streaming :(
View 2 Replies
View Related
Apr 24, 2014
How to change directory in c++ ( windows ) I want to go to the folder "example2" and I delete some files and then return to the original folder c++ - windows
View 7 Replies
View Related
Sep 26, 2012
this is the code:
Code:
#include <stdio.h>
#include <string>
#include <iostream>
using namespace std;
int main () {
int result,i,j;
[Code] ....
and it doesn't find it. it says the the word:"Users" is incorrectly formed universal character name ....
View 2 Replies
View Related
May 13, 2015
I've got an interface that provides the methods that are to be implemented
Code:
class A {
virtual void A() = 0;
}
class B : public A {
std::string operator<<(const std::string& lhs);
[Code] ....
I don't know why the << operator in B is never called..
View 5 Replies
View Related
May 19, 2013
how am i supposed to alter font size of text which appear in output screen?
View 1 Replies
View Related
Jun 15, 2013
if there is a program which i can use to change the name of a variable in a c program for example if i declare a variable like
Code:
int ch;
printf("%d", ch);
Can i later change the name of the ch variable to lets say "number" the code now becomes
Code:
int number;
printf("%d", number);
View 6 Replies
View Related
Oct 10, 2014
i have my basic C program here (i'm new to C language):
Code:
#include <stdio.h>
int main()
{
int grade;
int A=0;
int B=0;
int C=0;
int D=0;
int E=0;
[Code]....
As you can see, it's only for counting how many students got the grades from A to E, but the problem is that i need to change it from numbers into asterisk
for example: 4 students got the grade A, and 3 students got the grade B
instead of displaying
A=4
B=3
i want it to display
A=****
B=***
View 11 Replies
View Related
Jun 20, 2013
I have installed VS 2010 and VS 2012. VS 2012 uses SqlServer CE 3.5 and VS 2012 uses SqlServer CE 4.0.The problem is that when a project uses a 3.5 file it tries to open it with 4.0 even if the app.config says to use the 3.5 provider. The version of the assembly is pulled right out of the GAC. I uninstalled 4.0 and the reference auto updated its version to 3.5.1. However after installing 4.0 again it changes to 4.0. The error I am getting is that 4.0 cannot open a 3.5 file....they changed the file format from 3.5 to 4.0 and they are not compatible.
View 2 Replies
View Related
Dec 20, 2014
Is there a way to change the Font size using code?
View 5 Replies
View Related
Sep 4, 2014
On one of my assignments I have to find the optimal change. For example, if I were to have 70 cents and had only quarters, dimes and pennies, the best way to receive change using less coins all together would be 2 quarters and 2 dimes (4 coins all together should be displayed).
All in all, I understand my assignment, however there is something I don't know how to do (or can't recall how to) and that is finding the the highest number in an array to use in a function and be able to compare it.
#include<iostream>
using namespace std;
//function in which amount = money, changeArray is the array where money is stored,
//and numCoins the amount of coin types there are available in the array
int optimalChange(int amount, int * changeArray, int numCoins) {
[Code] .....
What I'm stuck with, is that I don't remember how to get the highest number from the array that way I can compare it with the total amount when I'm building my function. Also, the function has to call itself recursively.
View 1 Replies
View Related
Sep 13, 2013
So this is the code I have so far, I didn't know it had to be a dynamic array so how would I Utilize dynamic array allocation to size the modal array
#include <iostream>
using namespace std;
int main() {
const int arraySize = 25;
const int patternSize = 10;
[Code] ....
View 1 Replies
View Related
Oct 5, 2014
im new to c++ ,so my question is how do i change a length of a text. for example hi my name is blah blah blah. nice to meet you. (n i want every lines to have 8 chars how do i do that)
(hi__my__
name_is_
balh____
blah____
blah____
._nice__
to_meet_
you.) (_ equal space)
View 3 Replies
View Related
Sep 4, 2013
How to change what the cursor is in sfml 2.0?
View 1 Replies
View Related
Jun 16, 2014
I have a program with the following code, and I need to be able to either change the value of any or all of the strlen or to replace one or all with a temp array value. All values of the expression are arrays.
if (::strlen(tc_buf) + ::strlen(maxtime_buf) + ::strlen(" ") < sizeof(localBuf))
View 1 Replies
View Related