Oct 11, 2012 at 5:12pm UTC
Ok this is a very easy program and I'm an absolute beginner. I don't know where I am going wrong though.
//This program calculates Sales Tax.
Question 3, Page 81
Written by
#include <iostream>
using namespace std;
int main()
{
double purchase = 52;
double salestax = 52 * 0.04;
double countrytax = 52 * 0.02;
double total = purchase + salestax + countrytax;
cout << " Total Purchase:" << purchase <<endl;
cout << " Total Sales Tax: " << salestax << endl;
cout << "Total Country Tax:" << countrytax << endl;
cout << " Total: " << total << endl;
return 0;
}
Any help is much appreciated. I know it will be the stupidest of things I overlooked in the end.
Last edited on Oct 11, 2012 at 5:13pm UTC
Oct 11, 2012 at 5:17pm UTC
I'm afraid I don't see the problem. It compiles and runs fine for me. And the total is actually the sum of the purchase and taxes.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
#include <iostream>
using namespace std;
int main()
{
double purchase = 52;
double salestax = 52 * 0.04;
double countrytax = 52 * 0.02;
double total = purchase + salestax + countrytax;
cout << " Total Purchase:" << purchase <<endl;
cout << " Total Sales Tax: " << salestax << endl;
cout << "Total Country Tax:" << countrytax << endl;
cout << " Total: " << total << endl;
return 0;
}
Total Purchase:52
Total Sales Tax: 2.08
Total Country Tax:1.04
Total: 55.12
Last edited on Oct 11, 2012 at 5:18pm UTC
Oct 11, 2012 at 5:18pm UTC
I can run it just fine. What is your problem?
Oct 11, 2012 at 5:20pm UTC
This is the error message:
1>------ Build started: Project: SalesTax, Configuration: Debug Win32 ------
1>Build started 10/11/2012 1:19:54 PM.
1>InitializeBuildStatus:
1> Touching "Debug\SalesTax.unsuccessfulbuild".
1>ClCompile:
1> salesmain.cpp
1>c:\users\rvhu312012ur\desktop\salestax\salestax\salesmain.cpp(2): error C2143: syntax error : missing ';' before 'constant'
1>c:\users\rvhu312012ur\desktop\salestax\salestax\salesmain.cpp(2): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>
1>Build FAILED.
1>
Oct 11, 2012 at 5:26pm UTC
Haha, it took me a while to figure it out...
You need to put comments (
//
) in front of the text above #include <iostream>:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
//This program calculates Sales Tax.
//Question 3, Page 81
//Written by
#include <iostream>
using namespace std;
int main()
{
double purchase = 52;
double salestax = 52 * 0.04;
double countrytax = 52 * 0.02;
double total = purchase + salestax + countrytax;
cout << " Total Purchase:" << purchase <<endl;
cout << " Total Sales Tax: " << salestax << endl;
cout << "Total Country Tax:" << countrytax << endl;
cout << " Total: " << total << endl;
return 0;
}
Last edited on Oct 11, 2012 at 5:26pm UTC
Oct 11, 2012 at 5:30pm UTC
Oh man!! I feel so stupid right now. I always do something like this and then spend a good hour going nuts on trying to figure out what I did wrong. Thanks everyone for replying so quickly.
Oct 11, 2012 at 6:03pm UTC
Well your title did help me to widen my search.