- #1
Saladsamurai
- 3,020
- 7
Help with Simple C++ code please :)
So here is the idea of the program (I have comments in the code too)
Ask the user for a number up to 5 digits long, store it in a as a string array,reverse the order
of the number (i.e. if user enters 12345 make it 54321), convert the reversed string to an int type object, calculate the sqrt of the reversed number.
here is:
here is the compiler error message:
it occurs on the one-line block of code in the for loop
So here is the idea of the program (I have comments in the code too)
Ask the user for a number up to 5 digits long, store it in a as a string array,reverse the order
of the number (i.e. if user enters 12345 make it 54321), convert the reversed string to an int type object, calculate the sqrt of the reversed number.
here is:
Code:
//
// GEU 111
// Spring09
// /* Program to: Prompt user for a five-digit integer, reverse the order of the digits,
compute the sqrt of both the digit and the reversed digit */
#include <iostream>
#include <cmath>
#include <cstring>
using namespace std;
int main ()
{
char nString[5];
char rString[5];
int L;
cout << "Please enter a string of up to five digits \n";
cin.getline (nString, 6 ,'\n'); //Takes up to 5-digit string from user
L = strlen (nString); // Determines length of string entered
cout << "The number you entered is " << nString << endl << endl; //outputs string
for (int i=L; i<L; i++)
{
rString = nString[L-1-i]; // reverses nString ERROR OCCURS ON THIS LINE
}
atoi (rString); // Converts char rString to int nString
cout << rString << endl << endl;
system ("PAUSE");
return 0;
}
/* OUTPUT: */
here is the compiler error message:
Code:
line 34 D:\1NEU SPRING 09\GEU 111 FLASH\HW\hw7b_cpb.cpp incompatible types in assignment of `char' to `char[5]'
it occurs on the one-line block of code in the for loop