1. Print a message telling a user to press the letterToQuit key numPresses times
ID: 3561733 • Letter: 1
Question
1. Print a message telling a user to press the letterToQuit key numPresses times to quit. End with newline. Ex: If letterToQuit = 'q' and numPresses = 2, print:
Sample program:
Only provide the <STUDENT CODE> portion in the box below; do not provide an entire program.
2. Define a character variable letterStart. Read the character from the user, print that letter and the next letter in the alphabet. Sample output assuming the user enters 'a':
Sample program:
Only provide the <STUDENT CODE> portion in the box below; do not provide an entire program.
ive been struggling on these two problems forever. please help! i want to know what im doing wrong.
Explanation / Answer
// 1. Print a message telling a user to press the letterToQuit key numPresses times to quit. End with newline.
// Ex: If letterToQuit = 'q' and numPresses = 2, print:
// Press the q key 2 times to quit.
// Sample program:
#include <iostream>
using namespace std;
int main() {
char letterToQuit = '?';
int numPresses = 0;
cout << "Press the " <<letterToQuit <<" key " <<numPresses << " times to quit. " << endl;
return 0;
}
// Only provide the <STUDENT CODE> portion in the box below; do not provide an entire program.
// 2. Define a character variable letterStart. Read the character from the user, print that letter and the next letter in the alphabet.
// Sample output assuming the user enters 'a':
// ab
// Sample program:
#include <iostream>
using namespace std;
int main() {
char letterStart;
cin >> letterStart;
cout << letterStart << static_cast<char> (letterStart+1);
return 0;
}
//Only provide the <STUDENT CODE> portion in the box below; do not provide an entire program.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.