-6
#include <iostream>
#include <conio.h>

int main () 
{ 
int nNumber ;
std :: cout << "Type a number: ";
std :: cin >> nNumber ;
int a = 0.0 ;
const int b = 1-9 ;
const int c = 
{ 
if (nNumber <= 10)
{
    nNumber = c ;
}nNumber    
 } 
const int d ;
{
if (nNumber > 0 )
{
    nNumber = d ;
}
}
switch (nNumber) ;
{
case a : std :: cout << "else" ;
case b : std :: cout << "1 singn number" ;
case c : std :: cout << "2 sings number" ;
case d : std :: cout << "negative number" ;
}
getch () ;
}

I'm making an easy program and I don't know why I have so many errors. Can anyone help me? The program is supposed to ask the user to give him a number and after that match it to one of four group. I was trying to do that for 2 weeks but it doesn't work.

dptd
  • 274
  • 1
  • 3
  • 12
gabi 13
  • 17
  • 2
  • 7
    I suggest you pick a good book from [here](http://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list) and learn the basics. – vsoftco Sep 21 '15 at 04:10
  • 2
    Welcome to Stack Overflow! Please read the guide [How do I ask a good question](http://stackoverflow.com/help/how-to-ask), especially the part on Minimal, Complete, and Verifiable example (MCVE). This will help you solve problems for yourself. If you do this and are still stuck you can come back and post your MCVE, what you tried, and what the results were so we can better help you. – JeffC Sep 21 '15 at 04:10
  • Google translation from Polish : Podaj liczbe -> Enter the number, nLiczba -> nNumber, 1 singn number -> 1 singn number, 2 sings number -> 2 sings number – MikeCAT Sep 21 '15 at 04:23
  • What are "1 singn number" and "2 sings number"? – MikeCAT Sep 21 '15 at 04:24

2 Answers2

0

Here is the corrected code with explanations as comments

#include <iostream>
#include <conio.h>

int main () 
{ 
    int nNumber ;
    std :: cout << "Type a number: ";
    std :: cin >> nNumber ;
    int a = 0 ; // a is an integer so it can store integer values only
    const int b = 1-9 ;
      int c; // c cannot be constant since it is changing its value, constans cannot change value during execution
    if (nNumber <= 10) // no need of {} if only one code is there to execute and befre the if, They are used to separate a block of code
        nNumber = c ;
// }nNumber this is wrong , no use with this code, and u have put ; in statement end
      int d ;// d cannot be constant since it is changing its value, constans cannot change value during execution
    if (nNumber > 0 )
    { // this is not neccessary since only one line of code is there to execute, if more than one it is neccessary, I put this here only to show thiy way is also not wrong
        nNumber = d ;
    } // every { shpould be closed 

    switch(nNumber)  // switch should not cotain ; at this point, refer the syntax of switch case, every case should contain braek statement, otherwise it will not break after the exection of case, ie if case 2 executing it will continue the execution until a break found or end of the switch,(in switch case)
    {
    case 1: 
        std :: cout << "else" ;
        break;
    case 2 : std :: cout << "1 singn number" ;
        break;
    case 3 : std :: cout << "2 sings number" ;
        break;
    case 4 : std :: cout << "negative number" ;
        break;
    }
    getch () ;
}
Akhil V Suku
  • 870
  • 2
  • 13
  • 34
-1

Not knowing about the behavior, this code can successfully be compiled.

#include <iostream>
// not needed and generates error on some compilers
//#include <conio.h>
int main () 
{ 
    int nLiczba ;
    std :: cout << "Podaj liczbe" ;
    std :: cin >> nLiczba ;
    const int a = 0 ; // You shouldn't give real number to int, and make this const
    const int b = 1-9 ;
    const int c = 12345; // I don't know the right value
    { 
        if (nLiczba <= 10)
        {
            nLiczba = c ;
        }

    } 
    const int d = 67890; // I don't know the right value
    {
        if (nLiczba > 0 )
        {
            nLiczba = d ;
        }
    }
    switch (nLiczba) // remove junk semicolon
    {
        // add break;s
        case a : std :: cout << "else" ; break;
        case b : std :: cout << "1 singn number" ; break;
        case c : std :: cout << "2 sings number" ; break;
        case d : std :: cout << "negative number" ; break;
    }
    // not needed and generates error on some compilers
    //getch () ;
}
MikeCAT
  • 73,922
  • 11
  • 45
  • 70