This is my (Yehaa!! My first, more than 20 lines of code containing, more than 90% working) finished program.
It is a calculator, I made it just to practise. BUT!! it doesn't work!
Well, it does, but the outcome is 0!! No matter what I try, the outcome is 0 NULL ZERO!! How is this possible! I coun't find out why. Here is the source code, please tell me what I am doing wrong.
Code:
#include <iostream> //For cout and other basic stuff
#include <string.h> //For char and string
#include <stdlib.h> //For system pause.(I don't know if including headers uses memory, but it would be a waste of space if they would cuz I don't really need this one)
int main()
{
char confirm[2];
while (strcmpi("q", confirm))
{
cout<<"Druk op Q en dan op enter om het programma te beeindigen, druk op enter om door te gaan.\n"; //Press Q and than enter to quit, press enter to continue.
cin.getline(confirm, 2, '\n');
if (!strcmpi("q", confirm))
{
return 0;
}
else
{
char input[2];
cout<<"Wat wil je doen?? Twee cijfers: \nA: optellen.\nB: aftrekken.\nC: vermenigvuldigen\nD: delen.\n__________\n"; //What do you wish to do? A=Count two number. B=subtract two number C=Multiply two number D=Split two number. (?)
cin.getline(input, 2, '\n');
cout<<"__________\n";
if (!strcmpi("A", input))
{
cout<<"Je hebt ervoor gekozen om twee getallen op te tellen\n"; //You have chosen to count two numbers.
}
else if (!strcmpi("B", input))
{
cout<<"Je hebt ervoor gekozen om twee getallen af the trekken\n"; //You have chosen to subtract two numbers.
}
else if (!strcmpi("C", input))
{
cout<<"Je hebt ervoor gekozen om twee getallen te vermenigvuldigen\n"; //You have chosen to multiply two numbers.
}
else if (!strcmpi("D", input))
{
cout<<"Je hebt ervoor gekozen om twee getallen te delen\n"; //You have chosen to split two numbers.
}
else
{
cout<<"\n!!Error, bad imput, quitting!!\n";
cin.get();
return 0;
}
system("pause");
int x=0,y=0,z=0;
{
cout<<"Vul het eerste cijfer in: "; //Please enter the first number.
cin>>x;
cin.get();
cout<<"\nVul nu het tweede cijfer in: "; //please enter the second number.
cin>>y;
cin.get();
switch (input, '\n')
{
case 'A':
z=x+y;
break;
case 'B':
z=x-y;
break;
case 'C':
z=x*y;
break;
case 'D':
z=x/y;
break;
}
cout<<"__________\nDe uitkomst: "<<z<<"\n__________\n"; //The outcome: <<z<<; */ this is whre it goes wrong/*
}
}
}
}
The cout functions are written in dutch, but I translated them to english.
Please use [code][/code]Tags