PDA

View Full Version : Help First Time Visual Studio 2005 User



Noxious020189
03-04-2006, 04:41 PM
I know I posted about the <iostream> just the other day (yesterday), but as I said there it's just for the <iostream>, so I thought I would start a thread so that I learn as I go. I'm just trying to make simple programs, and I thought it would be nice if I could get some help on what to do when I'm stuck, and an explination would be nice to of why it's there and how it works. I do look up stuff in both "C++ For Dummies" (I know it's sad, but I bought this book when I had 56K and at a stupid age where I thought I knew everything). I also have the internet to look things up, but I need help from forums sometimes because users tend to explian the way I understand. So let me get this started:

First off:

using namespace std; ^What dose that do. I used it, and it made my code work.

Second off:

//PROGRAM WRITTER: Chris Kaliszewski
//PROGRAM NAME: Test Project
//PROGRAM START DATE: 03/03/06
//PROGRAM END DATE: TBA
#include<iostream>
using namespace std;
void main()
{
int No_of_Items, Per_Tax; //Declaring "Number of Items" and "Percentage of Tax" as an integer

cout <<"How many items will you be buying? "; //Asking "How many items will be bought"
cin >>No_of_Items; //Hold value for the "Number of Items"
cout <<"How much is tax? "; //Asking "How much tax is"
cin >>Per_Tax; //Hold value for the "Percentage of Tax"

double Real_Tax; //Declaring "Decimal Percentage" as a double
char Yes_No;

Real_Tax = Per_Tax * .01; //Multiplying Per_Tax by one tenth to get the "Decimal Percentage"

system("cls"); //Clears the screen

cout <<"Number of items: "<<No_of_Items<<'\n'; //Informs the user of what they entered for "Number of Items"
cout <<"Percentage of tax: "<<Per_Tax<<"\n\n"; //Informs the user of what they entered for "Percentage of Tax"
cout <<"Is that the correct data? (Please type Y or N) "; //Asking if the information is right
cin >>Yes_No; //Hold value for the "Yes or No"
cout <<"\n\n"; //New Lines(2)
return 0;
} ^Why won't that return work? Down below is what error I get. I looked up return, and by my understanding if I use "return 0" then it should return my code back up to the "void main()" function.

ERROR:
1>------ Build started: Project: Tax Calculator, Configuration: Debug Win32 ------
1>Compiling...
1>Tax Calculator.cpp
1>c:\documents and settings\owner\my documents\visual studio 2005\projects\tax calculator\tax calculator\tax calculator.cpp(28) : error C2562: 'main' : 'void' function returning a value
1> c:\documents and settings\owner\my documents\visual studio 2005\projects\tax calculator\tax calculator\tax calculator.cpp(7) : see declaration of 'main'
1>Build log was saved at "file://c:\Documents and Settings\Owner\My Documents\Visual Studio 2005\Projects\Tax Calculator\Tax Calculator\Debug\BuildLog.htm"
1>Tax Calculator - 1 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

eshbach
03-04-2006, 05:23 PM
main is void. void methods should not return anything. at this point you are trying to return an int (0), which is invalid.

geoff2k
03-04-2006, 05:36 PM
"using namespace std;" introduces everyting in the namespace "std", meaning instead of having to write:

std::cout << "blah blah" << std::endl;

you can write:

cout << "blah blah" << endl;

Noxious020189
03-04-2006, 06:08 PM
"using namespace std;" introduces everyting in the namespace "std", meaning instead of having to write:

std::cout << "blah blah" << std::endl;

you can write:

cout << "blah blah" << endl;

Thank you :)


main is void. void methods should not return anything. at this point you are trying to return an int (0), which is invalid.


I put int below, and look at the stages


//PROGRAM WRITTER: Chris Kaliszewski
//PROGRAM NAME: Test Project
//PROGRAM START DATE: 03/03/06
//PROGRAM END DATE: TBA
#include<iostream>
using namespace std;
int main()
{
int No_of_Items, Per_Tax; //Declaring "Number of Items" and "Percentage of Tax" as an integer

cout <<"How many items will you be buying? "; //Asking "How many items will be bought"
cin >>No_of_Items; //Hold value for the "Number of Items"
cout <<"How much is tax? "; //Asking "How much tax is"
cin >>Per_Tax; //Hold value for the "Percentage of Tax"

double Real_Tax; //Declaring "Decimal Percentage" as a double
char Yes_No;

Real_Tax = Per_Tax * .01; //Multiplying Per_Tax by one tenth to get the "Decimal Percentage"

system("cls"); //Clears the screen

cout <<"Number of items: "<<No_of_Items<<'\n'; //Informs the user of what they entered for "Number of Items"
cout <<"Percentage of tax: "<<Per_Tax<<"\n\n"; //Informs the user of what they entered for "Percentage of Tax"
cout <<"Is that the correct data? (Please type Y or N) "; //Asking if the information is right
cin >>Yes_No; //Hold value for the "Yes or No"
cout <<"\n\n"; //New Lines(2)
return 0;
}

Stages when run:

http://img209.imageshack.us/img209/9766/10fl1.jpg

http://img463.imageshack.us/img463/4074/22wm.jpg

^Shouldn't go back to

{
int No_of_Items, Per_Tax; //Declaring "Number of Items" and "Percentage of Tax" as an integer

cout <<"How many items will you be buying? "; ?

IF not please explain, and please show me how. I don't know what I'm doing wrong. Also I will clear screen, and do the if then statment when I get this figured out

eshbach
03-04-2006, 06:22 PM
a function is not a loop.

return means it returns a value to where it was called.

for instance you could say:

int temp = main(); and that would put the return value from main() in temp. (in this case, it would be the same as saying int temp = 0; ).

If you want your program to loop you need a "while" or a "for".

Noxious020189
03-04-2006, 06:32 PM
a function is not a loop.

return means it returns a value to where it was called.

for instance you could say:

int temp = main(); and that would put the return value from main() in temp. (in this case, it would be the same as saying int temp = 0; ).

If you want your program to loop you need a "while" or a "for".

I want it to go the user says no then go back to the questions again. So if I made that loop it would continusly do nothing. Once I get this working I want it to be something like a tax calculator (I should know how to do arrays). So when the user is done it will print something out like:

Item/t/tPrice/t/tTax on Item/t/tTotal Price for Item
-------------------------------------------------
C++ Book/t/t$29.99/t/t$1.80/t/t31.79


Sub Total: $29.99
Tax: $1.80
Total: $31.79

^Of course everything will be lined up, and there will be more items. I may think about asking the user if there is shipping or something along that line

BTW this is just a test program to get me to learn my way around this interface, and get me to know what I'm doing :) So thanks for all of your help . Sooner or later I want to get into the windows apps with the windows, and not console apps