C++ :: Cents Calculator - Declaring Values Of Dimes And Quarters
Feb 1, 2013
How to declare the values of the the dimes and quarters in my program. The purpose of it is to add up the total number in cents while at the same time making sure the program is universal to be used with different numbers.
Here is my code.
/*Take the number of dimes and quarters and get the total ammount of cents*/
#include <iostream>
using namespace std;
int main ( ) {
int dimes,quarters,result,amount_1,amount_2
int result;
[Code] ....
View 4 Replies
ADVERTISEMENT
May 29, 2012
I just wanted to know how to store big numbers (like more than 20 digit values) in a variable?
For those type of big values, whether float variable is good or int variable is good?
And finally, all these challenges i am facing in the process of coding for an application which contains calculator and it should give the accurate results as our windows pc calculator.
View 3 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 16, 2013
I haven't actually learned how to use arrays yet but I know the basic principle of it and decided to try and implement one to improve my code. I'm sure the thing is a bug ridden mess but I would particularly like to point your attention to the function sortDenomination(). Is what I am trying to do in the loop possible?
The reason why I want to do it this way and not with if statements for each denomination is because I can then easily apply this to the second part of the assignment which sees us split a double into dollars and cents and then process each separately. All I would have to differ for each is change the money_loop variable to include the last two denominations in the array.
Code:
#include <stdio.h>
/*Reads cents input from the user.*/
void getCents(int &read_cents) {
printf("Please enter the amount of cents between 5-95:
[Code] .....
View 10 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
Nov 6, 2014
I am putting a instance o the Vehicle Class inside the constructor of the Calculate Class then calling it later. I get a warning saying the variable is not used and a error when I try to used the functions from the vehicle class saying use of undeclared identifier.
Code:
#include <iostream>
#include "Calculate.h"
#include "Vehicle.h"
#include <fstream>
Calculate::Calculate(){
[Code] ....
View 9 Replies
View Related
Jun 5, 2013
I am a bit confused about how specific one must be with arguments when declaring a function. I'll show you two functions from the book I'm using to learn C to show you what I mean.
Example 1 (greatest common denominator function):
Code:
void gcd (int u, int v) {
int temp;
printf ( "
[Code] ....
So in that function, there are exactly two arguments, because that's how many arguments the algorithm to find the gcd takes. No problem there, makes sense to me. Then further in the chapter on functions I run into this,
Example 2 (square root function):
Code:
float absoluteValue (float x) {
if ( x < 0 )
x = -x;
return x;
[Code] ....
In this second example, we have a square root function that is preceded by an absolute value function. The absolute value function has the one argument, "float x", however when this function is called within the square root function, the arguments "guess * guess * -x" are passed to it. I'm confused how this absolute value function is working with all of that inside it, when it was originally declared with just "x." The only possibility I can think of is that this expression is treated as a single unit, but I'm not sure.
View 2 Replies
View Related
Apr 4, 2013
Code:
if (IS_LEAP_YEAR(year))
const int days_per_month[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
else
const int days_per_month[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; Is it ok to declare the array in this manner or is it bad?
And i have to ask the user for a date to enter in my program. So should I use scanf or should I store the date in a string and then use sscanf. I have to check for valid input for everything like day, month, year etc. I did it as below..
Code:
int assignments;
assignments = scanf("%d / %d / %d", &month, &day, &year);
fflush(stdin);
if (assignments != 3)
{
printf("Retry: ");
}
else
error checking.
View 9 Replies
View Related
Aug 1, 2013
Code:
#include <stdio.h>
int main(void){
int a=0;
for(;a<=10;)
int b;
return 0;
}
I have got a code like this. I don't expect to get an output but just assumed I would see the command screen until I terminated it. What I want to do is just declare a variable b in a endless loop. But what I got from the compiler is this error: error: expected expression before 'int'. I am using Code::Blocks and I think the compiler is GCC.
View 4 Replies
View Related
Jun 13, 2014
I'm using some rather large external libraries, and I want to load them in my .cpp file only. so, my header looks like this:
namespace {
// hidden declarations
namespace geometry {
class Point;
class Polygon;
class Box;
//etc
}
}
In the declaration of the main class in that header, I merely use these as pointers or references. The .cpp file looks as follows:
// Boost
#include <boost/geometry/geometry.hpp>
#include <boost/geometry/geometries/polygon.hpp>
#include <boost/geometry/geometries/point_xy.hpp>
#include <boost/geometry/multi/geometries/multi_polygon.hpp>
[Code] .....
This doesn't work however:
error C2371: '`anonymous-namespace'::geometry::Point' : redefinition; different basic types
1> e:..........NavigationMesh.h(10) : see declaration of '`anonymous-namespace'::geometry::Point'
What can I do to forward declare external classes like this?
View 13 Replies
View Related
Jun 30, 2014
We have been assigned to create an iTunes library. Everything compiles in my other .h file but my main is not happy with my object declaration. It keeps stating "primary expression before '{'". Here is my main code:
#include<iostream>
#include<string>
#include<fstream>
#include"myTunes.h"
using namespace std;
//function protocols
void read(string);
[Code] ......
View 1 Replies
View Related
Mar 18, 2013
I'm writing this program that basically interprets the rottentomatoes website. I am however having a problem declaring if it is rotten or fresh according to the rating the user enters.
I'm outputting it here:
void PrintAll(const string titles[], const int ratings[], int count) {
WriteLine('=', 50);
cout << "PRINT ALL" << endl;
WriteLine('-', 50);
[Code] .....
And here is my condition:
string RatingToString(const int ratings[], int count) {
string rank;
for(int i = 0; i < count; i++) {
[Code]....
Here is the output:
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
==================================================
MENU
1. Add Movie
2. Print All
3. Exit
--------------------------------------------------
Enter 1-3 : 1
Title : Hitch
Rating : 90
==================================================
[Code]....
My condition works when there is only one movie, but when I add more, it gives it the new movies "ROTTEN" or "FRESH" rank.
View 1 Replies
View Related
Sep 26, 2014
Is it permissible to declare, for example, `std::valarray<int&>`? If so, how do I initialize such if the `valarray` is a class member?
View 3 Replies
View Related
Oct 29, 2013
I have the following code:
struct mystruct {
char fieldA[5];
char fieldB[7];
};
void dosomething(struct mystruct* pms) {
[Code] ....
Is there any problem doing that, even for a C89/90 compiler?
View 3 Replies
View Related
Oct 21, 2012
I can not set the size of my array while running porgrama. Is there any way to do this in C + +?
---- code ------
#include <iostream>
#include <string>
using namespace std;
[Code].....
View 5 Replies
View Related
Sep 9, 2014
see these sample:
Code:
#include <iostream>
#include <string>
using namespace std;
class test{
public:
virtual void ola() {
[Code] .....
Like you see, i don't re-declare the 'ola' function in 'test1' class, only in 'test' class. The compiler tell me the 'ola' isn't member of 'test1'. in 'test' i put it 'virtual', but forgetting that, how can i override it without re-declare it?
View 10 Replies
View Related
Nov 12, 2012
This is a c program that is failing to compile. The error occurs in the calcLabs() function. The error called out is (btw, I'm using VS 2010): Error4error C2143: syntax error : missing ';' before 'type'
I don't understand why the compiler is not letting me declare variables in the calcLabs() function!
Code:
#include<stdio.h>
#include<stdlib.h>
void calcPercent(double *);
double calcLabs();
double calcExams();
double calcFinal();
char calcLetter(float);
[code]...
View 5 Replies
View Related
Apr 6, 2013
I am looking at functions still and can't see the point in declaring the function at the top of the program, and then defining later i.e.
Code:
#include <iostream>
int add (int x, int y) {
return x + y;
[Code] .....
I obviously don't have much real world experience with this and am interested to see where declaring and defining later would be useful and/or beneficial.
View 14 Replies
View Related
Mar 26, 2013
What are the possible problems if I declare a bunch of data types and never use them? Do they take up a lot of memory? Will they slow run time? If it is an array do I have to delete it at the end of the program? What if the array is defined inside a class and never used? Do I still have to delete it?
i.e.
Code: class declarearrays{
public:
double **darray;
double **darray2;
void function1();//function that initializes darray
void function2();//function that initializes darray2 with different parameters, may not be used.
};
View 1 Replies
View Related
Sep 14, 2013
I have a function
Code:
int exec_program(char * arguments[])
{
...
}
I can call it like this without a problem:
Code: char * uselessvariable[] = {"/bin/echo", "Testing", NULL};exec_program(uselessvariable);
However I get an error if I try to compile it like this:
Code: exec_program({"/bin/echo", "Testing", NULL});
How, in c, I can put this array inside of the argument in one line without having to name a new variable name?
View 2 Replies
View Related
Oct 23, 2013
I'm just wondering, why you have to set the length of the inner arrays declaring a function. In which moment does the code needs to be sure about the length of the inner arrays accessing an cell?
I came up with this question realizing the elements of the outer array beeing pointers to the first value of each inner array. Therefore I can access e.g. the first first element of the second inner array like this:
**(arr + 1) ...regardless of the length of any array to my mind.
parallel post: [URL]...
View 6 Replies
View Related
Apr 1, 2014
According to [URL] ....
" char myword[] = { 'H', 'e', 'l', 'l', 'o', '