---
title: "Lite konstiga fel."
type: "forum-thread"
url: "https://www.webforum.nu/amne/c-cpp/172434-lite-konstiga-fel"
topic: "C/C++"
topic_url: "https://www.webforum.nu/amne/c-cpp"
author: "lalja"
published: "2008-06-27T15:09:37.000Z"
updated: "2008-06-27T16:03:29.000Z"
replies: 4
views: 561
page: 1
pages: 1
language: "sv-SE"
site: "webForum — webforum.nu"
rights: "Upphovsrätten till varje inlägg tillhör dess författare."
attribution: "Citera som: webForum, https://www.webforum.nu/amne/c-cpp/172434-lite-konstiga-fel"
---

# Lite konstiga fel.

## #1 — lalja, 2008-06-27T15:09Z

Hallå alla. Håller på med lite basics program för att förstå c++ igen; har gjort ett litet uppehål, håller nu på med ett program jag gjorde förut. 
här får ni det.

```
#include <iostream>
#include <string>
using namespace std;
int iVal;
int iPlus;
int iPlus2;
int iMinus;
int iMinus2;
int pSumma;
int mSumma;

int main()
{
cout <<"Hello! What do you want to count? Plus =1 or Minus=2 ? (1/2)";
	cin >> iVal;
	system ("CLS");
	if (iVal==2)
	{
	cout <<" You choiced plus. Input the first number.(1-9)\n\n";
	cin >> iPlus;
	system ("cls");
	cout <<"Input the second number.(1-9)\n\n";
	cin >> iPlus2;
	system ("cls");
	pSumma = iPlus + iPlus2;
	cout <<" Result: " << pSumma << ". Thanks for using\n\n";
	cin.get();
	return main();
    }
	else if (iVal==2) 
	{
	cout <<" You choiced minus. Input the first number.(1-9)\n\n";
	cin >> iMinus;
	system ("cls");
	cout <<" Input second number.(1-9)\n\n";
	cin >> iMinus2;
	system ("cls");
	mSumma = iMinus - iMinus2;
	cout <<"Result: " << mSumma << ". Thanks for using\n\n";
	cin.get();
	return main();
	}
	cin.get();
	return 0;
	}
```

Felet är då att när jag trycker "2" och kommer in i minus delen så blir det endå plus? tror ju tyvär att detta e ett enkelt fel och att jag inte kan läsa mellan raderna?
vad är fel? jag har försökt och försökt med allt men ja lyckas inte lösa det?

Permalänk: https://www.webforum.nu/p/172434

## #2 — nitro2k01, 2008-06-27T15:21Z

```
#include <iostream>
#include <string>
using namespace std;
int iVal;
int iPlus;
int iPlus2;
int iMinus;
int iMinus2;
int pSumma;
int mSumma;

int main()
{
  cout <<"Hello! What do you want to count? Plus =1 or Minus=2 ? (1/2)";
  cin >> iVal;
  system ("CLS");
  [B]if (iVal==1)[/B]
    {
      cout <<" You chose plus. Input the first number.(1-9)\n\n";
      cin >> iPlus;
      system ("cls");
      cout <<"Input the second number.(1-9)\n\n";
      cin >> iPlus2;
      system ("cls");
      pSumma = iPlus + iPlus2;
      cout <<" Result: " << pSumma << ". Thanks for using\n\n";
      cin.get();
      return main();
    }
  [B]else if (iVal==2) [/B]
    {
      cout <<" You chose minus. Input the first number.(1-9)\n\n";
      cin >> iMinus;
      system ("cls");
      cout <<" Input second number.(1-9)\n\n";
      cin >> iMinus2;
      system ("cls");
      mSumma = iMinus - iMinus2;
      cout <<"Result: " << mSumma << ". Thanks for using\n\n";
      cin.get();
      return main();
    }
  cin.get();
  return 0;
}
```

Som du gissar är felet väldigt enkelt. Båda if-satserna letade efter 2. Jag passade för övrigt på att indentera koden bättre och rätta felstavningen "choiced".

Permalänk: https://www.webforum.nu/p/2120384

## #3 — lalja, 2008-06-27T15:33Z

Man tackar! Uppskattar till tusen, ska kolla den nu, men iaf, tack :D :D

Permalänk: https://www.webforum.nu/p/2120389

## #4 — lalja, 2008-06-27T16:02Z

Funkade klockrent. tack ännu en gång

Permalänk: https://www.webforum.nu/p/2120392

## #5 — Ledel, 2008-06-27T16:03Z

Edit: D'oh, det var ju gjort när jag hade postat det. Ta gärna bort det här  :r

Permalänk: https://www.webforum.nu/p/2120393

---

Tråden på webben: https://www.webforum.nu/amne/c-cpp/172434-lite-konstiga-fel
