Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › Very quick and easy question in C++
New Posts  All Forums:Forum Nav:

Very quick and easy question in C++ - Page 2

post #11 of 16
Thread Starter 
Quote:
Originally Posted by Midpipps View Post
We need more information posting your code could be a huge help come compilers treat things a little different. What version of code::blocks? are they both the same between your windows and linux machine? Have you tried making a new file and copy and pasting the code from one to the other? Have you tried manually compiling it from command line? We would love to help we just need information.
It's the exact same version of Code::Blocks on both Windows and Linux, 10.5.
Copy and pasting into a new file is useless, it still gives the same problem.
As for compiling it from the command line, especially on Windows, I don't know how to do it...

Anyway, here's my code, everything is in Portuguese, the variables themselves and everything else, but it should be minimally understandable.
Also note that it is not finished and as such does have incomplete stuff.

Code:
#include <iostream>
#include <cstdlib>

using namespace std;

void opcao1()
{
    cout << "O simbolo do Hélio é He.";
}

void opcao2()
{
    cout << "O número atómico do Hélio é 2.";
}

void opcao3()
{
    cout << "A massa atómica do Hélio é 4.";
}

void opcao4()
{
    cout << "A configuração electrónica do Hélio é 1s2.";
}

void opcao5()
{
    cout << "O número de protões do Hélio é 2.";
}

void opcao6()
{
    cout << "O numero de electrões do Hélio é 2.";
}

void erro1()
{
    cout << "Não introduziu um número válido." << endl;
    cout << "Por favor introduza outro numero. \
";

    int opcao;

    if (opcao == 1)
    opcao1();
    else
    if (opcao == 2)
    opcao2();
    else
    if (opcao == 3)
    opcao3();
    else
    if (opcao == 4)
    opcao4();
    else
    if (opcao == 5)
    opcao5();
    else
    if (opcao == 6)
    opcao6();
    else
    if (opcao != 1,2,3,4,5,6)
    erro1();
}

void menu()
{
    cout << "Bem-vindo. \
" << endl;
    cout << "Este programa permite mostrar uma ficha técnica do elemento Hélio da tabela periódica." << endl;
    cout << "Poderá escolher a partir das opções abaixo a secção que deseja ver. \
" << endl;

    cout << "1 - Simbolo;" << endl;
    cout << "2 - Nº atómico;" << endl;
    cout << "3 - Massa atómica;" << endl;
    cout << "4 - Configuração electrónica;" << endl;
    cout << "5 - Nº de protões;" << endl;
    cout << "6 - Nº de electrões; \
" << endl;

    cout << "Por favor introduza o número correspondente ao ponto que deseja ver." << endl;
    int opcao;
    cin >> opcao;
    cout << "\
";

    if (opcao == 1)
    opcao1();
    else
    if (opcao == 2)
    opcao2();
    else
    if (opcao == 3)
    opcao3();
    else
    if (opcao == 4)
    opcao4();
    else
    if (opcao == 5)
    opcao5();
    else
    if (opcao == 6)
    opcao6();
    else
    if (opcao != 1,2,3,4,5,6)
    erro1();
}

void erro2()
{
    cout << "Não introduziu um número válido." << endl;
    cout << "Por favor introduza outro numero. \
";

    int opcao;
    cin >> opcao;

    if (opcao == 0)
    menu();
    else
    if (opcao != 0)
    cout << "teste";
}

void inicio()
{
    cout << "Introduza 0 para voltar ao menu inicial." << endl;

    int opcao;
    cin >> opcao;

    if (opcao == 0)
    menu();
    else
    do
    {
        erro2();
    } while (opcao !=0);
}

int main()
{
    int opcao;

    menu();
    inicio();

    cout << endl;

    system("pause");
    return 0;
}
Quote:
Originally Posted by lloyd mcclendon View Post
i would lean towards your code blocks install on windows being ANSI only, lacking unicode support. or misconfigured, compiler flag, etc. i would uninstall the IDE, download the latest and greatest from their site, be sure it has unicode support baked in, and reinstall that.

you have windows and nix but code in windows ? windows is for gaming only...

and if i were you i would use eclipse with the CDT plugin
I already have the latest...

I would use Linux more, especially for programming, but I hate having to reboot to do work, and then reboot again to game, and so on...

Might try Eclipse though. I think I've never tried it before...

Quote:
Originally Posted by selectstriker2 View Post
im assuming you trying to use some version of visual studio?
No... I use Code::Blocks.
My desktop
(18 items)
 
  
CPUMotherboardGraphicsRAM
Intel Core 2 Quad Q6600 Gigabyte P35-DS3L XFX Radeon HD 5770 Team Group Xtreem Dark 
RAMRAMRAMHard Drive
Team Group Xtreem Dark Corsair  Corsair  Western Digital Caviar 500GB 7200RPM 16MB Cache 
Optical DriveCoolingOSMonitor
Samsung SH-S203N Tuniq Tower 120 Windows 8 Pro 64-bit LG IPS234V-PN 23" 
KeyboardPowerCaseMouse
Logitech Media Keyboard 600 NOX Urano 600W NZXT Apollo - black Microsoft Intellimouse Explorer 3.0 
Mouse PadAudio
Regular black rubber mouse pad Realtek HD Audio 
  hide details  
Reply
My desktop
(18 items)
 
  
CPUMotherboardGraphicsRAM
Intel Core 2 Quad Q6600 Gigabyte P35-DS3L XFX Radeon HD 5770 Team Group Xtreem Dark 
RAMRAMRAMHard Drive
Team Group Xtreem Dark Corsair  Corsair  Western Digital Caviar 500GB 7200RPM 16MB Cache 
Optical DriveCoolingOSMonitor
Samsung SH-S203N Tuniq Tower 120 Windows 8 Pro 64-bit LG IPS234V-PN 23" 
KeyboardPowerCaseMouse
Logitech Media Keyboard 600 NOX Urano 600W NZXT Apollo - black Microsoft Intellimouse Explorer 3.0 
Mouse PadAudio
Regular black rubber mouse pad Realtek HD Audio 
  hide details  
Reply
post #12 of 16
just checked on my computer windows vista 32 bit and visual studio professional edition and it has the same issue. I have not been able to find what is causing it yet but am trying sorry no help yet but working on it.
    
CPUMotherboardGraphicsRAM
Q6600 DG33TL XFX 6950 2GB 4gigs Corsair XMS2 DDR2 
Hard DriveOptical DriveOSMonitor
1.5TB seagate 2X640GB Samsung DVDRW Windows Vista & Debian Linux Samsung 19" + Acer 24" Wide 
KeyboardPowerCaseMouse
Microsoft SideWinder X6 Antec 750 TruePower Raidmax Smilodon COOLER MASTER Sentinel 
Mouse Pad
RocketFish 
  hide details  
Reply
    
CPUMotherboardGraphicsRAM
Q6600 DG33TL XFX 6950 2GB 4gigs Corsair XMS2 DDR2 
Hard DriveOptical DriveOSMonitor
1.5TB seagate 2X640GB Samsung DVDRW Windows Vista & Debian Linux Samsung 19" + Acer 24" Wide 
KeyboardPowerCaseMouse
Microsoft SideWinder X6 Antec 750 TruePower Raidmax Smilodon COOLER MASTER Sentinel 
Mouse Pad
RocketFish 
  hide details  
Reply
post #13 of 16
include this
#include <locale>

and inside your code
setlocale(LC_ALL, "portuguese-brazilian");

was about the best solution I could find without digging too deep I have heard that it can cause other issues with other locale specific things but have never used it or run into a need to use it before so use at your own risk. If this is for a school assignment I would query the instructor for more information. here is the reference i used http://www.cplusplus.com/reference/c...ale/setlocale/ and where I found the "portuguese" http://msdn.microsoft.com/en-US/libr...=VS.80%29.aspx

Bye the way posting code helps from your original explanation I thought you were talking about it converting from standard english characters to the portuguese characters
Edited by Midpipps - 2/23/11 at 8:48pm
    
CPUMotherboardGraphicsRAM
Q6600 DG33TL XFX 6950 2GB 4gigs Corsair XMS2 DDR2 
Hard DriveOptical DriveOSMonitor
1.5TB seagate 2X640GB Samsung DVDRW Windows Vista & Debian Linux Samsung 19" + Acer 24" Wide 
KeyboardPowerCaseMouse
Microsoft SideWinder X6 Antec 750 TruePower Raidmax Smilodon COOLER MASTER Sentinel 
Mouse Pad
RocketFish 
  hide details  
Reply
    
CPUMotherboardGraphicsRAM
Q6600 DG33TL XFX 6950 2GB 4gigs Corsair XMS2 DDR2 
Hard DriveOptical DriveOSMonitor
1.5TB seagate 2X640GB Samsung DVDRW Windows Vista & Debian Linux Samsung 19" + Acer 24" Wide 
KeyboardPowerCaseMouse
Microsoft SideWinder X6 Antec 750 TruePower Raidmax Smilodon COOLER MASTER Sentinel 
Mouse Pad
RocketFish 
  hide details  
Reply
post #14 of 16
Thread Starter 
Quote:
Originally Posted by Midpipps View Post
include this
#include <locale>

and inside your code
setlocale(LC_ALL, "portuguese-brazilian");

was about the best solution I could find without digging too deep I have heard that it can cause other issues with other locale specific things but have never used it or run into a need to use it before so use at your own risk. If this is for a school assignment I would query the instructor for more information. here is the reference i used http://www.cplusplus.com/reference/c...ale/setlocale/ and where I found the "portuguese" http://msdn.microsoft.com/en-US/libr...=VS.80%29.aspx

Bye the way posting code helps from your original explanation I thought you were talking about it converting from standard english characters to the portuguese characters
Wow, awesome, that worked! Thanks!

But I'm curious about something, do you know why the code worked fine in Linux without using that setlocale command, and why it didn't work correctly in Windows until I used that command?

Also, I'm sorry for not having posted the code before, I should've done that sooner... My English isn't exactly perfect, and in cases like this it can make stuff complicated.
My desktop
(18 items)
 
  
CPUMotherboardGraphicsRAM
Intel Core 2 Quad Q6600 Gigabyte P35-DS3L XFX Radeon HD 5770 Team Group Xtreem Dark 
RAMRAMRAMHard Drive
Team Group Xtreem Dark Corsair  Corsair  Western Digital Caviar 500GB 7200RPM 16MB Cache 
Optical DriveCoolingOSMonitor
Samsung SH-S203N Tuniq Tower 120 Windows 8 Pro 64-bit LG IPS234V-PN 23" 
KeyboardPowerCaseMouse
Logitech Media Keyboard 600 NOX Urano 600W NZXT Apollo - black Microsoft Intellimouse Explorer 3.0 
Mouse PadAudio
Regular black rubber mouse pad Realtek HD Audio 
  hide details  
Reply
My desktop
(18 items)
 
  
CPUMotherboardGraphicsRAM
Intel Core 2 Quad Q6600 Gigabyte P35-DS3L XFX Radeon HD 5770 Team Group Xtreem Dark 
RAMRAMRAMHard Drive
Team Group Xtreem Dark Corsair  Corsair  Western Digital Caviar 500GB 7200RPM 16MB Cache 
Optical DriveCoolingOSMonitor
Samsung SH-S203N Tuniq Tower 120 Windows 8 Pro 64-bit LG IPS234V-PN 23" 
KeyboardPowerCaseMouse
Logitech Media Keyboard 600 NOX Urano 600W NZXT Apollo - black Microsoft Intellimouse Explorer 3.0 
Mouse PadAudio
Regular black rubber mouse pad Realtek HD Audio 
  hide details  
Reply
post #15 of 16
Its possible that the compiler automatically detected a specific setting in windows that caused it to assume that you wanted to work under a specific cultures guidelines for reading/displaying text.


Conversely, perhaps Linux automatically detected the correct one.

Lots of rules when it comes to cultures, text, encoding and the likes.
My System
(13 items)
 
  
CPUMotherboardGraphicsRAM
I5 760 GA-H55N GTX 470 PNY Optima 8GB 
Hard DriveMonitorPowerCase
Spinpoint F4 LG227WTG sg07 PSU Sugo sg07 
Mouse
CM Sentinel 
  hide details  
Reply
My System
(13 items)
 
  
CPUMotherboardGraphicsRAM
I5 760 GA-H55N GTX 470 PNY Optima 8GB 
Hard DriveMonitorPowerCase
Spinpoint F4 LG227WTG sg07 PSU Sugo sg07 
Mouse
CM Sentinel 
  hide details  
Reply
post #16 of 16
Quote:
Originally Posted by KaiZ51 View Post
Wow, awesome, that worked! Thanks!

But I'm curious about something, do you know why the code worked fine in Linux without using that setlocale command, and why it didn't work correctly in Windows until I used that command?

Also, I'm sorry for not having posted the code before, I should've done that sooner... My English isn't exactly perfect, and in cases like this it can make stuff complicated.
I think mykah89 has a better one then I could give you. Like I said I never ran into that issue before so it was a great learning experience for me too. Code is a universal language for the most part
    
CPUMotherboardGraphicsRAM
Q6600 DG33TL XFX 6950 2GB 4gigs Corsair XMS2 DDR2 
Hard DriveOptical DriveOSMonitor
1.5TB seagate 2X640GB Samsung DVDRW Windows Vista & Debian Linux Samsung 19" + Acer 24" Wide 
KeyboardPowerCaseMouse
Microsoft SideWinder X6 Antec 750 TruePower Raidmax Smilodon COOLER MASTER Sentinel 
Mouse Pad
RocketFish 
  hide details  
Reply
    
CPUMotherboardGraphicsRAM
Q6600 DG33TL XFX 6950 2GB 4gigs Corsair XMS2 DDR2 
Hard DriveOptical DriveOSMonitor
1.5TB seagate 2X640GB Samsung DVDRW Windows Vista & Debian Linux Samsung 19" + Acer 24" Wide 
KeyboardPowerCaseMouse
Microsoft SideWinder X6 Antec 750 TruePower Raidmax Smilodon COOLER MASTER Sentinel 
Mouse Pad
RocketFish 
  hide details  
Reply
New Posts  All Forums:Forum Nav:
  Return Home
  Back to Forum: Coding and Programming
Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › Very quick and easy question in C++