| | |
trying to make a program to say the change due back after a purchase is made
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Oct 2007
Posts: 2
Reputation:
Solved Threads: 0
trying to make a program to say the change due back after a purchase is made.
this is what i have so far but it doesn't want to work so i really could use some help please.
this is what i have so far but it doesn't want to work so i really could use some help please.
C++ Syntax (Toggle Plain Text)
#include <iostream> #include <string> // do not remove /******************************************************************** * User Include Files * ********************************************************************/ #include "sapi.h" // do not remove using namespace std; /******************************************************************** * User Defined Constants * ********************************************************************/ /******************************************************************** * Function Prototypes * ********************************************************************/ void speech(string texttovoice); /******************************************************************** * Function name: main * * Date Written : * * * * Purpose: Provides an entry point to our program. * * * * Arguments: NONE * * * * Return Value: integer * * * ********************************************************************/ int main () { int money, onedollar, fiftycent, twentycent, tencent, fivecent, purchase, payment, penny; Speech ("Enter the amount of purchase \n"); cin << purchase; speech ("Enter the amount of payment \n"); cin << payment; change(money, onedollar, twentyfivecent, tencent, fivecent, penny); cout << "One Dollar: " << onedollar << endl; cout << "twentyfive Cent: " << twentyfivecent << endl; cout << "Ten Cent: " << tencent << endl; cout << "five Cent: " << fivecent << endl; cout << "pennys: " << penny << endl; return 0; } int change(float money, int onedollar, int twentyfivecent, int tencent, int fivecent, int penny); { float temp; temp = payment - purchase; temp *= 100; speech ("onedollar = temp/100"); temp = temp%100; speech ("twentyfivecent = temp/25"); temp = temp%25; speech("tencent = temp/10"); temp = temp%10; speech( "fivecent = temp%5"); temp = temp/5; speech( "penny = temp/1"); return 0; } /******************************************************************** * Function name: speech * * Date Written : 9/2/2005 * * * * Purpose: To take a string of characters that has been passed in * * as arguments and output them to the screen and the * * speakers. Will only allow 1000 characters to be passed * * in to form a word/sentence. * * * * Arguments: texttovoice the string to be outputted to the * * screen and the speakers * * * * Return Value: NONE * * * * Written by: Dr Toni Logar and Roger Schrader * * * ********************************************************************/ void speech( string texttovoice) { int i; // index used for conversion WCHAR wstring[1000]; // used to hold convert string ISpVoice* Voice = NULL; // The voice interface // convert the string to a wide character string array // and NULL terminate the string i = 0; while( i < (int)texttovoice.size() && i < 999) { wstring[i] = texttovoice[i]; i++; } wstring[i]='\0'; // Initialize COM CoInitialize ( NULL ); // Create the voice interface object CoCreateInstance ( CLSID_SpVoice, NULL, CLSCTX_ALL, IID_ISpVoice, (void**)&Voice ); // Speak! Output the words to the screen Voice->Speak(wstring,SPF_DEFAULT,NULL); // Shutdown the voice if ( Voice != NULL ) Voice -> Release (); Voice = NULL; // Shutdown COM CoUninitialize (); // Output the word to the screen cout << texttovoice; }
Last edited by Ancient Dragon; Oct 10th, 2007 at 11:31 pm. Reason: add code tags
Re: trying to make a program to say the change due back after a purchase is made
0
#2 Oct 10th, 2007
>>but it doesn't want to work
by that I guess you mean it will not compile. What are the compile errors? What lines won't compile?
I know for a fact that lines 38 and 40 are wrong. -- using << instead of >>
also purchase and payment variables should probably be floats not ints
Another obvious problem -- you did not prototype function change(). It must be prototyped at the top of the program if you call it before it is coded. Just like variables have to be declared before used, functions have to be prototyped (or coded) before called.
by that I guess you mean it will not compile. What are the compile errors? What lines won't compile?
I know for a fact that lines 38 and 40 are wrong. -- using << instead of >>
also purchase and payment variables should probably be floats not ints
Another obvious problem -- you did not prototype function change(). It must be prototyped at the top of the program if you call it before it is coded. Just like variables have to be declared before used, functions have to be prototyped (or coded) before called.
Last edited by Ancient Dragon; Oct 10th, 2007 at 11:40 pm.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
•
•
Join Date: Oct 2007
Posts: 2
Reputation:
Solved Threads: 0
Re: trying to make a program to say the change due back after a purchase is made
0
#3 Oct 11th, 2007
anymore help also i have no idea what prototype is because we haven't learned it yet
•
•
•
•
>>but it doesn't want to work
by that I guess you mean it will not compile. What are the compile errors? What lines won't compile?
I know for a fact that lines 38 and 40 are wrong. -- using << instead of >>
also purchase and payment variables should probably be floats not ints
Another obvious problem -- you did not prototype function change(). It must be prototyped at the top of the program if you call it before it is coded. Just like variables have to be declared before used, functions have to be prototyped (or coded) before called.
Last edited by jerdawg89; Oct 11th, 2007 at 1:29 pm.
Re: trying to make a program to say the change due back after a purchase is made
0
#4 Oct 11th, 2007
>anymore help also i have no idea what prototype is because we haven't learned it yet
This is a function definition:
Note that it has no semicolon after the argument list but it defines a body. This is a prototype:
Notice that it has no body, but it does have a semicolon after the argument list. A prototype is designed to declare the name, return type, and parameters of a function so that you can use it without having to define it first. The golden rule is that everything has to be declared before you can use it. That means this is very wrong, and shouldn't compile:
Why? Because foo wasn't declared before you used it. You can fix the problem by moving the definition before the use (because a definition is also a declaration):
But that's not always practical. This is where prototypes come in:
Now foo is declared before you use it, and you can still define it wherever you want.
This is a function definition:
C++ Syntax (Toggle Plain Text)
int change(float money, int onedollar, int twentyfivecent, int tencent, int fivecent, int penny) { float temp; // ... return 0; }
C++ Syntax (Toggle Plain Text)
int change(float money, int onedollar, int twentyfivecent, int tencent, int fivecent, int penny);
C++ Syntax (Toggle Plain Text)
int main() { foo(); } int foo() { return 0; }
C++ Syntax (Toggle Plain Text)
int foo() { return 0; } int main() { foo(); }
C++ Syntax (Toggle Plain Text)
int foo(); int main() { foo(); } int foo() { return 0; }
I'm here to prove you wrong.
![]() |
Similar Threads
- Make a VB Program run in the background? (VB.NET)
- Make my own IM program and MySpace Clone. (PHP)
- End if statements (Visual Basic 4 / 5 / 6)
- "net user [username [password | *]" (Windows NT / 2000 / XP)
- Can I make my C program understand that a key has been pressed? (C++)
- DevC++ Help (C++)
- How to make my program detecct when the computer is going to LOGOFF or SHUTDOWN (C)
- how can i make the program depend on time (C)
- Help needed In creating application to make business cards (Java)
Other Threads in the C++ Forum
- Previous Thread: binary file into class using dynamic arrays
- Next Thread: I need the helps, the deadline is coming soon...
| Thread Tools | Search this Thread |
api array arrays based beginner binary c++ c/c++ calculator char class classes code compile compiler console conversion count delete deploy desktop directshow dll download dynamic dynamiccharacterarray encryption error file forms fstream function functions game getline givemetehcodez google graph gui homeworkhelp homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker linux list loop looping loops map math matrix memory news number output parameter pointer problem program programming project proxy python random read recursion recursive reference return rpg string strings struct temperature template templates test text text-file tree unix url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






