Why are my variables not initializing

Hey, worlds worst programmer here with another(hopefully) simple question. I'm trying to create a palindrome using five variables. Only problem is that the feedback says they aren't initializing for some reason.

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
42
43
44
45
   // Lab 2, Programming Conventions, to read and print two sets of inputs, with two calculated values.
  // Programmer: 
  // Editor(s) used: XP Notepad
  // Compiler(s) used: VC++ 2010 Express

 // preprocessor directive for streaming, variable, and ending statement.
#include <iostream>
using std::cin;
using std::cout;
using std::ios;
using std::endl;

  // preprocessor directive for string, and variable string.
#include <string>
using std::string;
using std::getline;

int main() {

  //Jesse Burns program number 1: the basics.
  cout << "Lab 1, Programming Basics" <<endl;
  cout << "Programmer: " <<endl;
  cout << "Editor(s) used: XP Notepad" <<endl;
  cout << "Compiler(s) used: VC++ 2010 Express" <<endl;

  int num1;
  int num2;
  int num3;
  int num4;
  int num5;
  string buf;

  cout << "Enter a number to determine a palindrome or Q to quit:"<<endl;
  cin >> buf; num1,num2,num3,num4,num5 = atoi(buf.c_str());
  cin.ignore(1000,10);
  
  if(num1 == num5 && num2 == num4)
  {
	  cout << num1 << num2 << num3 << num4 << num5 << "is a palindrome"<<endl;
	
  }
	 else if (buf == "Q" || buf == "q")
	 
	 cin.get();
  }


I honestly can't understand why. Everything seems to check out fine on my end. Any pointers?
You need #include <stdlib.h> for atoi()
 
num1,num2,num3,num4,num5 = atoi(buf.c_str());


This seems strange to me.

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

do {
  cin >> buf; 

  if (buf == "Q" || buf == "q")
    break;

  bool isPalindrome = true;

  for ( size_t i = 0; i < buf.size() / 2; i++ ) {

    if ( buf[ i ] != buf[ buf.size() - i - 1 ] ) {

      isPalindrome = false;
      break;

    }

  }

  if ( isPalindrome ) {

    cout << buf << "is a palindrome"<<endl;
	
  } else {

    cout << buf << "is not a palindrome"<<endl;

  }

} while ( buf != "Q" && buf != "q" )
	
Last edited on
Topic archived. No new replies allowed.