Take your previous assignment (the character array part) and convert it over to
ID: 3703578 • Letter: T
Question
Take your previous assignment (the character array part) and convert it over to C++. All printfs should be couts. All scanfs need to be cins. All character arrays should be using strings. Note: Do not put a + in your filename for your program. Moodle does not like special characters in filenames and will corrupt your assignment. #define _CRT_SECURE_NO_WARNINGS #include #include #include #include #define MAX_STRING_LENGTH 80 void main(void) { char userInput[MAX_STRING_LENGTH]; printf("Please enter a sentence "); scanf("%[^ ]", userInput); for (int i = 0; i < strlen(userInput); i++) { if (isdigit(userInput[i])) { printf("%c", userInput[i]); } } printf(" "); system("pause");//from stdlib }
Explanation / Answer
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include<bits/stdc++.h>
#define MAX_STRING_LENGTH 80
using namespace std;
void main(void)
{
stringg userInput;
cout <<"Please enter a sentence" << endl;
cin >>userInput;
for (int i = 0; i < userInput.size(); i++)
{
if (isdigit(userInput[i]))
{
cout <<userInput[i];
}
}
cout << endl;
system("pause");
//from stdlib
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.