Author |
Message |
kinghellz Guest
Offline
|
Posted: Sat Oct 06, 2007 8:39 pm Post maybe stupid Post subject: help me with c++ |
 |
|
|
|
im just learning c++, and working on my small project minicalculator, for some reason when i add any two numbers i get answer like 121545123157 instead of a real answer which is 10 or 20. If you can find any errors in my code il be apreciated
/*my first program after not pragraming for a year
ShellExecute(NULL, "open", "http://a3studio.4t.com", NULL, NULL, SW_SHOWNORMAL); this command brings u to this website
*/
#include <iostream>
#include <stdlib.h>
#include <windows.h>
using namespace std;
#define PI 3.14 //defines pi so pie now = to 3.14
int main()
{
SetConsoleTitle("Mini Calculator"); // title
SetCursorPos(0,0); //cursor position
HANDLE text; //handle variable
text = GetStdHandle(STD_OUTPUT_HANDLE); //make it that
SetConsoleTextAttribute(text,FOREGROUND_GREEN); //text attribute
menu:
int choice;
cout<<"Welcome to MiniCalculator \n\n";
cout<<"Type in 1 and press enter to add"<<endl;
cout<<"Type in 2 and press enter to subtract"<<endl;
cout<<"Type in 3 and press enter to multiply"<<endl;
cout<<"Type in 4 and press enter to divide"<<endl;
cout<<"Type in 5 and press enter to find area/perimiter of a circle"<<endl;
cout<<"Type in 6 and press enter to go to google.com"<<endl;
cout<<"Type in 7 and press enter to exit"<<endl;
cout<<"Type in your choice and press enter: ";
cin>>choice;
switch (choice){
case 1:
int a;
int b;
int c;
c = a + b;
cout<<"\n\n Type in and press enter the number you want to add to: ";
cin>>a;
cout<<"\n\n Now type in and press enter the number you want to add: ";
cin>>b;
cout<<"The Result is "<<c<<".\n\n\n\n";
system("pause");
cout<<"n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n";
goto menu;
}
return 0;
}
[quote][/quote] |
|
|
Back to top |
|
 |
kinghellz Guest
Offline
|
Posted: Sat Oct 06, 2007 8:46 pm Post maybe stupid Post subject: |
 |
|
|
|
oh yea its not finished so dont say i missed out the rest 2-7 choices |
|
Back to top |
|
 |
Bak ?ls -s 0 in

Age:26 Gender: Joined: Jun 11 2004 Posts: 1826 Location: USA Offline
|
Posted: Sat Oct 06, 2007 10:24 pm Post maybe stupid Post subject: |
 |
|
|
|
c++ programs are executed in order, one line at a time. So when you do "c = a + b" it takes whatever is in a and b at that point in the program and stores in in c.
so doing something like
is perfectly legal and would print out 10. The program first puts 5 into c, then 10, then prints out c, which is 10. _________________ SubSpace Discretion: A Third Generation SubSpace Client |
|
Back to top |
|
 |
baseball43v3r Seasoned Helper
Joined: Jan 02 2006 Posts: 102 Offline
|
Posted: Sun Oct 07, 2007 12:56 am Post maybe stupid Post subject: |
 |
|
|
|
basically what he is saying is that you have to move this line:
c = a + b;
after you input a and b. and then you output c. |
|
Back to top |
|
 |
Bak ?ls -s 0 in

Age:26 Gender: Joined: Jun 11 2004 Posts: 1826 Location: USA Offline
|
Posted: Sun Oct 07, 2007 1:51 am Post maybe stupid Post subject: |
 |
|
|
|
NEVERMIND I GOT CONFUSED |
|
Back to top |
|
 |
tcsoccerman Server Help Squatter
Age:33 Gender: Joined: Jan 15 2007 Posts: 694 Location: Atlantis Offline
|
Posted: Sun Oct 07, 2007 1:41 pm Post maybe stupid Post subject: |
 |
|
|
|
Quote: | cout<<"n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"; |
lol |
|
Back to top |
|
 |
|