0
Having some typing issues on compiler practice as c++
Hi so when I try rewriting the practice session in the C++ compiler for the practice Fluffy pancakes because it says to "declare i" somewhere before the condition statement. Tried using int i, didn't do anything. So I'll need help. P.S Also when I'm on the desktop it just wiped out complier practice when try editing the coding. There is another issue but I just refresh the page lol.
6 Respuestas
+ 2
a range-based for loop is a good alternative if you want a concise way to iterate arrays.
for (const auto b : breakfasts){
cout << b << endl;
}
https://en.cppreference.com/w/cpp/language/range-for
+ 1
Oh thanks! I like things to be concise. Other than that I'll just read keywords.
+ 1
Oh ok thanks Bob
0
can we see your code?
0
#include <iostream>
using namespace std;
int main() {
string breakfasts[] = {"Cinnamon Doughnuts", "Waffles", "Granola",
"Chorizo Burrito", "French Toast"};
string newItem = "Fluffy Pancakes";
int index;
cin >> index;
breakfasts [index] = newItem;
for (i = 0; i <= 4; i++){
cout << breakfasts << endl;
}
}
0
you are missing the datatype of i in your for loop.
you are also missing the indexing for breakfasts.
for(int i = 0; i <=4; i++){
⬆️this ⬇️ also this
cout << breakfasts[i] << endl;
}