C++ Error

K

koolyio

I've been having trouble with my script that uses a do...while loop
and a for loop to calculate subtotals, gst, and totals. I'm making it
for my parents. They own a bar/hotel. And for the caclulations part,
leave tham as is (gst = sub / 107 * 7). Also, I've been having trouble
using the system("PAUSE"); command. My compiler (Dev-C++ 4) says
'implicit declaration of function int system(...)' or something along
those lines. Any help will be greatly appriceiated and give some
credit in the code, thanks!

CODE:
#include <iostream.h>

//define variables
float nums[100];
float sub;
float tot;
float tottax;
float gst;
int howmany;
int i=0;
int a=1;
char x;
//begin application
int main()
{
//title
cout << " w e l c o m e t o . . .\n";
cout << " M y C a l C\n";
//legal stuff
cout << "Welcome to MyCalc. This program is designed to be\n";
cout << "used for commercial buisness and is free under GPL\n";
cout << "Side Note:\n";
cout << " If you get MORE THAN TWO DECIMAL PLACES, use ONLY the\n";
cout << " FIRST TWO decimal places. Thank You!\n\n\n";
cout << "Type Anything And Press Enter to Continue: ";
cin >> x;
cout << "\n\n";
//how many
do
{
if (howmany>100)
{
cout << "Sorry! The number cannot be over a hundred!";
}
cout << "How many numbers will be adding together today?\n";
} while (howmany>100);
for (a ==> howmany)
{
cout << "Enter number #" << a << ": $";
cin >> nums;
sub = nums + sub;
i++;
a++;
}
//total and taxes
gst = sub * 7 / 107;
tot = sub + gst;
//results
cout << "\n\n";
cout << "Your subtotal is: $" << sub << "\n";
cout << "Your GST is: $" << gst << "\n";
cout << "Your total is: $" << tot << "\n";
cout << "Type Anything And Press Enter to Exit: ";
cin >> x;
return 0;
}

Please E-mail the answer to (e-mail address removed)
 
J

John Harrison

koolyio said:
I've been having trouble with my script that uses a do...while loop
and a for loop to calculate subtotals, gst, and totals. I'm making it
for my parents. They own a bar/hotel. And for the caclulations part,
leave tham as is (gst = sub / 107 * 7). Also, I've been having trouble
using the system("PAUSE"); command. My compiler (Dev-C++ 4) says
'implicit declaration of function int system(...)' or something along
those lines.

That's because you need to include <stdlib.h>

Other comments below.
Any help will be greatly appriceiated and give some
credit in the code, thanks!

CODE:
#include <iostream.h>

//define variables
float nums[100];
float sub;
float tot;
float tottax;
float gst;
int howmany;
int i=0;
int a=1;
char x;
//begin application
int main()
{
//title
cout << " w e l c o m e t o . . .\n";
cout << " M y C a l C\n";
//legal stuff
cout << "Welcome to MyCalc. This program is designed to be\n";
cout << "used for commercial buisness and is free under GPL\n";
cout << "Side Note:\n";
cout << " If you get MORE THAN TWO DECIMAL PLACES, use ONLY the\n";
cout << " FIRST TWO decimal places. Thank You!\n\n\n";
cout << "Type Anything And Press Enter to Continue: ";
cin >> x;
cout << "\n\n";
//how many
do
{

You never input the value of howmany.

Presumably you want something like

cout << "How many figures do you want to enter ";
cin >> howmany;

But its not a good design to ask how many numbers. A better way would be to
say, "input zero when you have finished", that way your parents don't have
to count up how many numbers they want to input before they use your
program.
if (howmany>100)
{
cout << "Sorry! The number cannot be over a hundred!";
}
cout << "How many numbers will be adding together today?\n";
} while (howmany>100);
for (a ==> howmany)

while (a <= howmany)
{
cout << "Enter number #" << a << ": $";
cin >> nums;
sub = nums + sub;
i++;
a++;
}
//total and taxes
gst = sub * 7 / 107;
tot = sub + gst;
//results
cout << "\n\n";
cout << "Your subtotal is: $" << sub << "\n";
cout << "Your GST is: $" << gst << "\n";
cout << "Your total is: $" << tot << "\n";
cout << "Type Anything And Press Enter to Exit: ";
cin >> x;
return 0;
}


Hope your parents find it useful.

john
 
J

John Harrison

But its not a good design to ask how many numbers. A better way would be to
say, "input zero when you have finished", that way your parents don't have
to count up how many numbers they want to input before they use your
program.

Another point. There is no good reason to use an array in this program. You
can add up the number in an ordinary variable. Like this

float number;

cout << "Enter number #" << a << ": $";
cin >> number;
sub = number + sub;

Then there is no need for a limit of 100 numbers.

john
 
B

Bill Seurer

koolyio said:
I've been having trouble with my script that uses a do...while loop
and a for loop to calculate subtotals, gst, and totals. I'm making it
for my parents. They own a bar/hotel. And for the caclulations part, .. . .
for (a ==> howmany)

This is NOT C++ code. That's the problem.
 
K

Karl Heinz Buchegger

John said:
Another point. There is no good reason to use an array in this program. You
can add up the number in an ordinary variable. Like this

float number;

Just a nitpicking sidemark:

Since the OP is dealing with monetary values, float isn't a good
choice. If the OP wants to use floating point variables, then
at last he should use double. But better would be to not use
floating point arithmetic at all. The fiscal authorities have
no mercy, not even if only pennies are missing.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,164
Messages
2,570,898
Members
47,440
Latest member
YoungBorel

Latest Threads

Top