Hello I am kind of new to C++ and the programming stuff and I really want to learn it. So I went to the library and loaned some books and im halfway through the first book, and now I encountered a problem wich i've been struggeling for weeks with and now I finally chosed to register to this website and was looking for answers from other programmers.
Keep in mind (i figure this is a kind of newbie question so please dont flame me)
Im supposed to do a kind of a easy calculator thingie, and I stuck with this switch case where if I choose ex. "3"it should multiply ex. "6=3*2" get it? :P
maybe its better if I show.
this is how the code looks like.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
|
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int val,b,c; // val = switch variable and -b- and -c- (i figured u needed 2 variables for this) is whatever chosen to be added)
cout <<"Meny"<<endl<<endl;
cout <<"1=Addera"<<endl;
cout <<"2=Subtrahera"<<endl;
cout <<"3=Multiplicera"<<endl;
cout <<"4=Dividera"<<endl;
cout <<"Ange ditt val: "<<endl;
cin >> val;
switch (val)
{
case 1: c=b+b; // if chosen 1 ex. 2=1+1
break;
case 2: c=b-b; // if chosen 2 ex. 0=1-1
break;
case 3: c=b*b; // if chosen 3 ex. 8=4*2
break;
case 4: c=b/b; // if chosen 4 ex. 4=8/2
break;
}
cout <<"Ange ett tal"<<endl; //this is where a number is to be put.
cin >> b;
cout <<"Ange ett tal till"<<endl; // and this is where its either multiplied or added or whatever.
cin >> b;
cout <<"Summan blir "<< c <<endl; // this is where it will show the sum of the both numbers.
cout <<"Starta om programmet för att få se menyn igen";
system ("PAUSE");
return EXIT_SUCCESS;
}
|
thats how I build it and when I try it out (in an console application that is) i get.
this program is swedish so if you see some miss-spelled stuff dont flame me
"
Meny
1=Addera
2=Subtrahera
3=Multiplicera
4=Dividera
Ange ditt val: 1 (i choosed 1 for this)
1
Ange ett tal
5
Ange ett tal till
10
Summan blir
5242512
________________________________________________________________________________
The problem is the sum.. why do i get "5242512" as a sum when i clearly chosed "+" and i typed 5+10 its supposed to be 15??? right?
please help me and also
type how to fix
and
where to fix where the syntax were wrong =)
Thank you all so much for reading and thank you all for helping.
oh and one more thing. i would be pleased if you showed me the "right" code