Hi everyone... im using C++ Microsoft visual studio and would appreciate if you can help me out here. Ive been trying to do this the whole day ... and canttt figure it outtt PLEASEE HELPPP!! I am a total beginner so sorry if i have very stupid mistakes.
Code:#include <iostream> #include <cmath> #include <string> using namespace std; int main() { int odd = 0; int oddsum = 0; int x; int n=0; int oddx2 = 0; string code = "7896550100164702"; // Reversing the code order code = string(code.rbegin(), code.rend()); cout << "The reverse of your code is: " << code << endl; // Finding the sum of the odd positions // First multiply each number by 2 // If the result is less than 10, then sum it // If the result is 10 or greater, then add the two digits which make this 2 digit number, e.g. 12 = 1+2 cout << "The Odd Positions Of This Code are as follow: " << endl; for(int x=1; x<code.length(); x+=2) { cout << code.at(x) << endl; oddsum += code[x] - '0'; } cout << "The sum of the digits in the odd position = " << oddsum << endl; oddx2 = oddsum*2; cout << oddx2; cout << endl; for(int x=1; x<code.length(); x+=2) { ??????????????????????????????????????????? {
I am very stuck at the red part, i dont know how to write this part where i have to multiply the odd positions by 2 and decide if it is greater than 9.
I managed to sum the odd positions though that is not useful![]()



LinkBack URL
About LinkBacks
!! I am a total beginner so sorry if i have very stupid mistakes.


